
2014年1月12日 星期日
2013年5月5日 星期日
2013年3月27日 星期三
Turn on Monitor and Off scren saving by VB.NET
' ON/OFF screen saving
Private SPI_SETSCREENSAVERACTIVE As Integer = 17
Private SPIF_SENDWININICHANGE As Integer = 2
Dim hWnd As Long
_
Public Shared Function SystemParametersInfo(ByVal intAction As Integer, _
ByVal intParam As Integer, _
ByVal strParam As String, _
ByVal intWinIniFlag As Integer) As Integer
End Function
' Turn ON/OFF Monitor
Const WM_SYSCOMMAND = &H112&
Const SC_MONITORPOWER = &HF170&
' VB6 宣告之 Long 得改成 Int32 (Integer)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Int32)
SendMessage(Me.Handle.ToInt32, WM_SYSCOMMAND, SC_MONITORPOWER, 2&) ' Turn off monitor
SendMessage(Me.Handle.ToInt32, WM_SYSCOMMAND, SC_MONITORPOWER, -1&) ' 啟動螢幕
SystemParametersInfo(SPI_SETSCREENSAVERACTIVE, 0, Nothing, SPIF_SENDWININICHANGE) ' Off screen saving
Private SPI_SETSCREENSAVERACTIVE As Integer = 17
Private SPIF_SENDWININICHANGE As Integer = 2
Dim hWnd As Long
Public Shared Function SystemParametersInfo(ByVal intAction As Integer, _
ByVal intParam As Integer, _
ByVal strParam As String, _
ByVal intWinIniFlag As Integer) As Integer
End Function
' Turn ON/OFF Monitor
Const WM_SYSCOMMAND = &H112&
Const SC_MONITORPOWER = &HF170&
' VB6 宣告之 Long 得改成 Int32 (Integer)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Int32)
SendMessage(Me.Handle.ToInt32, WM_SYSCOMMAND, SC_MONITORPOWER, 2&) ' Turn off monitor
SendMessage(Me.Handle.ToInt32, WM_SYSCOMMAND, SC_MONITORPOWER, -1&) ' 啟動螢幕
SystemParametersInfo(SPI_SETSCREENSAVERACTIVE, 0, Nothing, SPIF_SENDWININICHANGE) ' Off screen saving
2013年1月20日 星期日
Transfor file by COM Port
Sub TransforFiles(ByVal sendFile As String)
Dim bys As Byte() = My.Computer.FileSystem.ReadAllBytes(sendFile)
Dim cx = bys.Length
Dim T1 As Integer = 0
Dim Clength As Integer
If cx > 4096 Then
Dim count As Integer = cx \ 4096
Do While T1 < count + 1
Clength = cx - (T1 * 4096)
If Clength > 4096 Then Clength = 4096
SerialPort1.Write(bys, T1 * 4096, Clength)
System.Threading.Thread.Sleep(500)
TextBox1.AppendText(T1.ToString + "Send No." + Clength.ToString + vbNewLine)
T1 = T1 + 1
Loop
Else
SerialPort1.Write(bys, 0, cx)
TextBox1.AppendText("Send " + cx.ToString)
End If
End Sub
Read text file by VB.net
Dim FileNum As Integer
Dim strTemp as String
FileNum = FreeFile()
FileOpen(FileNum, "C:\Test.txt", OpenMode.Input)
Do Until EOF(FileNum)
strTemp &= LineInput(FileNum) & vbNewLine
Loop
FileClose(FileNum)
Dim strTemp as String
FileNum = FreeFile()
FileOpen(FileNum, "C:\Test.txt", OpenMode.Input)
Do Until EOF(FileNum)
strTemp &= LineInput(FileNum) & vbNewLine
Loop
FileClose(FileNum)
2012年11月3日 星期六
How to use aboutBox in C sharp
1.Add aboutBox1
2.set parameter
this.Text = String.Format("About {0} {0}", AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("Version {0} {0}", AssemblyVersion);
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;
3. active it
AboutBox1 abc=new AboutBox1() ;
abc.ShowDialog();
2.set parameter
this.Text = String.Format("About {0} {0}", AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("Version {0} {0}", AssemblyVersion);
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;
3. active it
AboutBox1 abc=new AboutBox1() ;
abc.ShowDialog();
2012年10月29日 星期一
Recieve Data from serial port by C sharp
void AddRecieve(object s, EventArgs e)
{
textBox2.AppendText("進入!Received" + "\n");
int count;
int i = 0;
do
{
count = serialPort1.BytesToRead;
System.Threading.Thread.Sleep(200);
i += 1;
}
while (i < 19);
byte[] rxBuff = new byte[count];
int[] wordss = new int[18];
serialPort1.Read(rxBuff, 0, rxBuff.Length);
string str = BitConverter.ToString(rxBuff);
textBox2.AppendText(str + " i=" + i + "\n");
System.IO.File.AppendAllText(@"WriteLines.txt", str + " i=" +i + "\n");
string[] words = str.Split('-');
i = 0;
foreach (string word in words)
{
textBox2.AppendText(word + " ");
wordss[i] = Convert.ToInt16(word, 16);
i++;
}
// int decValue;
textBox1.Text = wordss[1].ToString();
textBox3.Text = (Convert.ToSingle(wordss[3]) + (Convert.ToSingle(wordss[4])) / 10).ToString();
textBox4.Text = (Convert.ToSingle(wordss[5]) + (Convert.ToSingle(wordss[6])) / 10).ToString();
double xValue = (Convert.ToDouble(wordss[7]) + (Convert.ToDouble(wordss[8])) / 10.0);
if (xValue >= 128.0)
{
xValue = 128.0 - xValue;
}
double yValue = (Convert.ToDouble(wordss[9]) + (Convert.ToDouble(wordss[10])) / 10.0);
if (yValue >= 128.0)
{
yValue = 128.0 - yValue;
}
double zValue = (Convert.ToDouble(wordss[11]) + (Convert.ToDouble(wordss[12])) / 10.0);
if (zValue >= 128.0)
{
zValue = 128.0 - zValue;
}
textBox5.Text = String.Format("{0:0.0}", xValue);
textBox6.Text = String.Format("{0:0.0}", yValue);
textBox7.Text = String.Format("{0:0.0}", zValue);
//wordss[11].ToString() + wordss[12].ToString();
string NowTime = String.Format("{0:yyyy/M/d HH:mm:ss}", DateTime.Now);
writeLog(NowTime, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text);
textBox2.AppendText("\n");
}
訂閱:
文章 (Atom)