查看: 1225|回复: 10
|
怎样制GUI?
[复制链接]
|
|
发表于 26-11-2006 10:24 PM
|
显示全部楼层
-能打入的资料只能是号码
-寄出的资料是ACSII码吧了.如下
- 0 = 00001100
- 1 = 10001100
- 2 = 01001100等
你要:
0 代表:0011 0000 (0x30)
1 代表:0011 0001 (0x31)
2 代表:0011 0010 (0x32)
9 代表:0011 1001 (0x39)
对吗?
注:Serial port 送出一个byte, 有10bit, Start bit+ 8 databit + Stop bit
我假定你是用FPGA并明白以上的。
希望有人可以帮帮我,因为我对 microsoft visual basic一窍不通.只学过 C Programming 吧了...谢谢...
我帮你起个头了,其他就靠你自己了。
源码下载:lock.zip |
|
|
|
|
|
|
|
楼主 |
发表于 26-11-2006 10:46 PM
|
显示全部楼层
哇,你差不多帮我做完了....非常谢谢你咧...
原帖由 pic 于 26-11-2006 10:24 PM 发表
你要:
0 代表:0011 0000 (0x30)
1 代表:0011 0001 (0x31)
2 代表:0011 0010 (0x32)
9 代表:0011 1001 (0x39)
对吗?
注:Serial port 送出一个byte, 有10bit, Start bit+ 8 datab ...
对了..0011 0000是binary code.假设是 D7D6D5D4D3D2D1D0 ,电脑寄出ASCII码时会变成 D0D1D2D3D4D5D6D7 的serial sequence.所以我才写成 0000 1100.
请问刚才那个code你帮我限制不能打alphabet吗?因为我的 FPGA只接收数字吧了.. |
|
|
|
|
|
|
|
发表于 27-11-2006 12:28 AM
|
显示全部楼层
顺便问一下:
我也是用visual c++ 6.0来做GUI
我得用serial communication 来 interface external devices.
请问有什么class library 是给 serial com 的??
我知道有 mscom control using active X, CserialPort....
请问哪个容易些??有没有教如何用serial communication 的网页(step by step)?? 我是beginner, PIC 大哥能教我吗??急。。
另外,Cserialport 有提到 See the Win32 SDK documentation for further details。 请问哪里可以下载这 win32 sdk 呢??
谢了 |
|
|
|
|
|
|
|
发表于 27-11-2006 09:31 AM
|
显示全部楼层
请问刚才那个code你帮我限制不能打alphabet吗?因为我的 FPGA只接收数字吧了..
请加入以下的code:(源码下载已更新)
- Private Sub txtPassword_Change(Index As Integer)
- ' Exit if text box is blank
- If txtPassword(Index).Text = "" Then Exit Sub
- ' check if number is enter
- If Asc(txtPassword(Index).Text) >= &H30 And Asc(txtPassword(Index).Text) <= &H39 Then
-
- ' Auto advanced to next password char
- If Index < 3 Then
- txtPassword(Index + 1).SetFocus
- End If
- Else
- txtPassword(Index) = ""
- End If
- End Sub
- '==================================================
- Private Sub txtPassword_KeyPress(Index As Integer, KeyAscii As Integer)
- '-------------------------
- ' if <back space> key is press
- If KeyAscii = 8 Then
- txtPassword(Index).Text = ""
- ' Auto advanced to next password char
- If Index > 0 Then
- txtPassword(Index - 1).SetFocus
- End If
- End If
- '-------------------------
- ' if <Enter> is press
- If KeyAscii = 13 Then
- ' Back to previous password char
- If Index > 0 Then
- Call cmdSend_Click ' Send when enter is press
- End If
- End If
- End Sub
复制代码
|
|
|
|
|
|
|
|
发表于 27-11-2006 09:33 AM
|
显示全部楼层
原帖由 南极星 于 27-11-2006 12:28 AM 发表
顺便问一下:
我也是用visual c++ 6.0来做GUI
我得用serial communication 来 interface external devices.
请问有什么class library 是给 serial com 的??
我知道有 mscom control using active X, Cseria ...
用MSComm ActiveX比较容易。
有没有教如何用serial communication 的网页(step by step)??
Google:MScomm tutorial 应该可以找到一大堆。
我学MSComm时是看VB6 的MSComm tutorial, 看example学的。
Visual C++ 我没有,也不熟悉。 |
|
|
|
|
|
|
|
楼主 |
发表于 27-11-2006 10:06 AM
|
显示全部楼层
原帖由 pic 于 27-11-2006 09:31 AM 发表
请加入以下的code:(源码下载已更新)
Private Sub txtPassword_Change(Index As Integer)
' Exit if text box is blank
If txtPassword(Index).Text = "" Then Exit Sub
' check if numb ...
我还想问你最后一样东西...那个send是打一个号码按一次send,还是打完四个才send?因为是四个号码一组才能去next state...每个号码怎样加delay呢?因为stop bit过后没停下,怕我的FPGA跑久后会开始有问题.就是讲:
0(8 bits data)1 (delay 1ms)0(8 bits data) 1 (delay 1ms)0(8 bits data) 1 (delay 1ms)0(8 bits data)1
0 start bit
1 stop bit
一个 8 bits data就是一个号码了...谢谢
[ 本帖最后由 男朋友 于 27-11-2006 02:30 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 27-11-2006 04:26 PM
|
显示全部楼层
原帖由 男朋友 于 27-11-2006 10:06 AM 发表
我还想问你最后一样东西...那个send是打一个号码按一次send,还是打完四个才send?因为是四个号码一组才能去next state...每个号码怎样加delay呢?因为stop bit过后没停下,怕我的FPGA跑久后会开始有问题.就是讲: ...
打完四个才send。
- ' For Sleep command
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- #If Win32 Then
- Private Declare Function GetTickCount Lib "kernel32" () As Long
- #Else
- Private Declare Function GetTickCount Lib "kernel" () As Long
- #End If
- Call Sleep(1) ' delay (1ms)
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 27-11-2006 07:48 PM
|
显示全部楼层
原帖由 pic 于 27-11-2006 04:26 PM 发表
打完四个才send。
' For Sleep command
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#If Win32 Then
Private Declare Function GetTickCount Lib " ...
不好意思,是加在哪里?我放下去会有error的... |
|
|
|
|
|
|
|
发表于 27-11-2006 10:17 PM
|
显示全部楼层
原帖由 男朋友 于 27-11-2006 07:48 PM 发表
不好意思,是加在哪里?我放下去会有error的...
加在cmdSend_Click 和第一行。
- ' For Sleep command
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- Private Sub cmdConnect_Click()
- ' Use COM1.
- MSComm1.CommPort = 1
- ' 9600 baud, no parity, 8 data, and 1 stop bit.
- MSComm1.Settings = "9600,N,8,1"
- ' Tell the control to read 1 byte buffer when Input
- ' is used.
- MSComm1.InputLen = 1
- ' Open the port.
- MSComm1.PortOpen = True
-
- MsgBox "Connected", vbInformation
- End Sub
- Private Sub cmdExit_Click()
- End
- End Sub
- Private Sub cmdSend_Click()
- If MSComm1.PortOpen = False Then
- MsgBox "Please connect.", vbCritical
- Exit Sub
- End If
- Dim x
- ' Send password to controller
- For x = 0 To 3
- MSComm1.Output = txtPassword(Index).Text
- Call Sleep(1) ' delay approx 1ms
- Next x
- MsgBox "Data send", vbInformation
- End Sub
- Private Sub Timer1_Timer()
- '- 00000001=??Please Enter Password To Lock? Door Unlocked
- '- 00000010=??Please Reenter Password? Door Unlocked
- '- 00000100=??Please Enter Password To Unlock? Door Locked
- Dim word
- ' If there is data in buffer
- If MSComm1.InBufferCount > 0 Then
- word = MSComm1.Input
- Else
- Exit Sub
- End If
- word = Left(word, 1)
- If word = &H1 Then '00000001
- lblStatus.Caption = "Please Enter Password To Lock"
- txtStatus.Text = "Door Unlocked"
- End If
- If word = &H2 Then '00000010
- lblStatus.Caption = "Please Reenter Password"
- txtStatus.Text = "Door Unlocked"
- End If
- If word = &H4 Then '00000100
- lblStatus.Caption = "Please Enter Password To Unlock"
- txtStatus.Text = "Door Locked"
- End If
- End Sub
- Private Sub txtPassword_Change(Index As Integer)
- ' Exit if text box is blank
- If txtPassword(Index).Text = "" Then Exit Sub
- ' check if number is enter
- If Asc(txtPassword(Index).Text) >= &H30 And Asc(txtPassword(Index).Text) <= &H39 Then
-
- ' Auto advanced to next password char
- If Index < 3 Then
- txtPassword(Index + 1).SetFocus
- End If
- Else
- txtPassword(Index) = ""
- End If
- End Sub
- Private Sub txtPassword_KeyPress(Index As Integer, KeyAscii As Integer)
- '-------------------------
- ' if <back space> key is press
- If KeyAscii = 8 Then
- txtPassword(Index).Text = ""
- ' Auto advanced to next password char
- If Index > 0 Then
- txtPassword(Index - 1).SetFocus
- End If
- End If
- '-------------------------
- ' if <Enter> is press
- If KeyAscii = 13 Then
- ' Back to previous password char
- If Index > 0 Then
- Call cmdSend_Click ' Send when enter is press
- End If
- End If
- End Sub
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 27-11-2006 10:49 PM
|
显示全部楼层
原帖由 pic 于 27-11-2006 10:17 PM 发表
加在cmdSend_Click 和第一行。
' For Sleep command
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub cmdConnect_Click()
' Use COM1.
MS ...
哦...谢谢你..你住马六甲吧...得空请你喝茶 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|