佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1225|回复: 10

怎样制GUI?

[复制链接]
发表于 26-11-2006 05:46 PM | 显示全部楼层 |阅读模式


请问要怎样用microsoft visual basic 6.0制如上图的GUI?
-Connect是用来接去 Serial Port的,就是通过Serial Port接收及寄出资料
-能打入的资料只能是号码
-寄出的资料是ACSII码吧了.如下
- 0 = 00001100
- 1 = 10001100
- 2 = 01001100等
-接收的资料如下,
- 00000001=显示Please Enter Password To Lock及 Door Unlocked
- 00000010=显示Please Reenter Password及 Door Unlocked
- 00000100=显示Please Enter Password To Unlock及 Door Locked
-stop bit 是1,start bit是0

希望有人可以帮帮我,因为我对 microsoft visual basic一窍不通.只学过 C Programming 吧了...谢谢...

[ 本帖最后由 男朋友 于 26-11-2006 10:26 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 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:(源码下载已更新)

  1. Private Sub txtPassword_Change(Index As Integer)

  2. ' Exit if text box is blank
  3. If txtPassword(Index).Text = "" Then Exit Sub

  4. ' check if number is enter
  5. If Asc(txtPassword(Index).Text) >= &H30 And Asc(txtPassword(Index).Text) <= &H39 Then
  6.    
  7.     ' Auto advanced to next password char
  8.     If Index < 3 Then
  9.         txtPassword(Index + 1).SetFocus
  10.     End If
  11. Else
  12.     txtPassword(Index) = ""
  13. End If

  14. End Sub
  15. '==================================================
  16. Private Sub txtPassword_KeyPress(Index As Integer, KeyAscii As Integer)

  17. '-------------------------
  18. ' if <back space> key is press
  19. If KeyAscii = 8 Then
  20.     txtPassword(Index).Text = ""
  21.     ' Auto advanced to next password char
  22.     If Index > 0 Then
  23.         txtPassword(Index - 1).SetFocus
  24.     End If
  25. End If

  26. '-------------------------
  27. ' if <Enter> is press
  28. If KeyAscii = 13 Then
  29.     ' Back to previous password char
  30.     If Index > 0 Then
  31.         Call cmdSend_Click ' Send when enter is press
  32.     End If
  33. End If

  34. 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++ 我没有,也不熟悉。
回复

使用道具 举报

Follow Us
 楼主| 发表于 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。


  1. ' For Sleep command
  2. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

  3. #If Win32 Then
  4.     Private Declare Function GetTickCount Lib "kernel32" () As Long
  5. #Else
  6.     Private Declare Function GetTickCount Lib "kernel" () As Long
  7. #End If


  8.    Call Sleep(1) ' delay (1ms)

复制代码
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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 和第一行。


  1. ' For Sleep command
  2. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

  3. Private Sub cmdConnect_Click()
  4.    ' Use COM1.
  5.    MSComm1.CommPort = 1
  6.    ' 9600 baud, no parity, 8 data, and 1 stop bit.
  7.    MSComm1.Settings = "9600,N,8,1"
  8.    ' Tell the control to read 1 byte buffer when Input
  9.    ' is used.
  10.    MSComm1.InputLen = 1
  11.    ' Open the port.
  12.    MSComm1.PortOpen = True
  13.    
  14.     MsgBox "Connected", vbInformation

  15. End Sub

  16. Private Sub cmdExit_Click()
  17. End
  18. End Sub

  19. Private Sub cmdSend_Click()

  20. If MSComm1.PortOpen = False Then
  21.     MsgBox "Please connect.", vbCritical
  22.     Exit Sub
  23. End If
  24. Dim x
  25. ' Send password to controller
  26. For x = 0 To 3
  27.     MSComm1.Output = txtPassword(Index).Text
  28.     Call Sleep(1) ' delay approx 1ms
  29. Next x

  30. MsgBox "Data send", vbInformation
  31. End Sub

  32. Private Sub Timer1_Timer()
  33. '- 00000001=??Please Enter Password To Lock? Door Unlocked
  34. '- 00000010=??Please Reenter Password? Door Unlocked
  35. '- 00000100=??Please Enter Password To Unlock? Door Locked

  36. Dim word
  37. ' If there is data in buffer
  38. If MSComm1.InBufferCount > 0 Then
  39.     word = MSComm1.Input
  40. Else
  41.     Exit Sub
  42. End If

  43. word = Left(word, 1)

  44. If word = &H1 Then '00000001
  45.     lblStatus.Caption = "Please Enter Password To Lock"
  46.     txtStatus.Text = "Door Unlocked"
  47. End If

  48. If word = &H2 Then '00000010
  49.     lblStatus.Caption = "Please Reenter Password"
  50.     txtStatus.Text = "Door Unlocked"
  51. End If

  52. If word = &H4 Then '00000100
  53.     lblStatus.Caption = "Please Enter Password To Unlock"
  54.     txtStatus.Text = "Door Locked"
  55. End If



  56. End Sub


  57. Private Sub txtPassword_Change(Index As Integer)

  58. ' Exit if text box is blank
  59. If txtPassword(Index).Text = "" Then Exit Sub


  60. ' check if number is enter
  61. If Asc(txtPassword(Index).Text) >= &H30 And Asc(txtPassword(Index).Text) <= &H39 Then
  62.    
  63.     ' Auto advanced to next password char
  64.     If Index < 3 Then
  65.         txtPassword(Index + 1).SetFocus
  66.     End If
  67. Else
  68.     txtPassword(Index) = ""
  69. End If

  70. End Sub

  71. Private Sub txtPassword_KeyPress(Index As Integer, KeyAscii As Integer)

  72. '-------------------------
  73. ' if <back space> key is press
  74. If KeyAscii = 8 Then
  75.     txtPassword(Index).Text = ""
  76.     ' Auto advanced to next password char
  77.     If Index > 0 Then
  78.         txtPassword(Index - 1).SetFocus
  79.     End If
  80. End If

  81. '-------------------------
  82. ' if <Enter> is press
  83. If KeyAscii = 13 Then
  84.     ' Back to previous password char
  85.     If Index > 0 Then
  86.         Call cmdSend_Click ' Send when enter is press
  87.     End If
  88. End If

  89. 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 ...


哦...谢谢你..你住马六甲吧...得空请你喝茶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 5-2-2025 07:49 PM , Processed in 0.111545 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表