|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Coding String from Com Port into Access
I am trying to capture a String from the Com Port and bring that string into Access.....I have hooked the GPS Unit up to the Com Port and can read the string from inside HyperTerminal. Does anyone have any sample code or any thoughts to the code I have below. This code was also donated (Thanks nofriends). I thank you all for your help.
The $GPGGA is the leading characters from the NMEA Sentence Information I have a form set up in Access that retrieves data from a database, allows the user to input new records etc. Can I place this code in the code window of that form? I thought of writing that to a seperate function and calling it "On Click". Does that make sense? CODE: Private Sub MSComm1_OnComm() Select Case MSComm1.CommEvent Case "$GPGGA" buffer = MSComm1.Input MsgBox StrConv(buffer, vbUnicode) Case Else MsgBox "Unknown error or event" End Select End Sub |
|
#2
|
|||
|
|||
|
Coding String from Com Port into Access
I am not sure I have the right Object Library turned on....Does anyone know what Object LIbrary I should activate.
I thank you for your help....I am very new to this.... |
|
#3
|
||||
|
||||
|
is it showing the Unkown error or event msg the whole time?
the input will look something like this? $GPGGA bla bla bla
__________________
Look! Its a ShemZilla ![]() ![]()
|
|
#4
|
||||
|
||||
|
Hi Jay,
I only have the comm control on my form, do you have something like this in the form_load event? its to initialize and open the comm port: Code:
if (Not MSComm0.PortOpen) Then
' Buffer to hold input string
Dim Instring As String
' Use COM1.
MSComm0.CommPort = 1
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm0.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input is used.
MSComm0.InputLen = 0
' Open the port.
MSComm0.PortOpen = True
' Send the attention command to the modem.
MSComm0.Output = "AT" & vbCr ' Ensure that the modem responds with "OK".
' Wait for data to come back to the serial port.
Buffer$ = Buffer$ & MSComm0.Input
MsgBox "SMS Port Open", vbOKOnly, "Port State"
Else
MsgBox "SMS Port Already Open", vbOKOnly, "Port State"
End If
make sure that you have something like this on load so that it gets opened and initiliazed |
|
#5
|
||||
|
||||
|
and have something like this in the onComm event:
Code:
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Buffer = MSComm1.Input
If InStr(Buffer, "$GPGGA") > 0 Then 'check to see if the command has $GPGGA in front
msgbox Buffer
End If
Case Else
MsgBox "Unknown error or event"
End Select
End Sub
you must use event in the case, that the actual input, and then use instr to check if that pre-leading chars are there. hope this helps |
|
#6
|
|||
|
|||
|
Code String from Com Port
When I place this code into my ACCESS FORM, below all my other code I dont get anything. Nothing happens....
Input : $GPGGA,17034,456345.8976,N,345646,W,1,05,280.2,M,-34.0,M,,,*75 There should be a total of 14 commas.... I should be good placing this code write in the Code Window in my form right? |
|
#7
|
|||
|
|||
|
Coding
Do I need to set up the Settings below and Open the port?
What about clearing the port....do you know how this is accomplished Code: MSComm.Settings = "9600, n, 8 , 1" MSComm.CommPort = 1 PortStatus = MSComm.PortOpen If Not PortStatus = True Then MSComm.PortOpen = True End If |
|
#8
|
||||
|
||||
|
hi, put the first section in the form load event, in the code window, and double click on the comm control, then it should take you to the on_Comm event and place the 2nd section of code there.
that should do the trick ![]() |
|
#9
|
|||
|
|||
|
I created a MODULE in Access and place the code in there. I am not getting error when I run teh Module...
Run Time Error '424' Object Required. Could this be a result of not having the correct Object Library loaded? |
|
#10
|
|||
|
|||
|
Ok Ill Try That
|
|
#11
|
||||
|
||||
|
Jay, I have only limited experience in this, only started with a project and left it
![]() You'll need to open the port in the code using the code you posted, that should go in the form load event. hope this helps |
|
#12
|
|||
|
|||
|
I placed your Com Port code in my Form under Form Load event and I am getting the same error.....this is all the code I have sitting on my Form. I commented all the code in the form load except for the Msg Box and that came out fine. SO to problem that is occuring is inthe first line of code. Thats where my debuger keeps bring me back to which is prety vague....I think it does not like "MSComm0.PortOpen"
Run Time Error '424' Object Required. I cannot thank you enough for your help here.....I am really stuck.....I have ben trying to find information on this and cant seem to find it. I despertaly want to learn this and am learning a lot..... CODE: Option Compare Database Private Sub Form_Load() If (Not MSComm0.PortOpen) Then ' Buffer to hold input string Dim Instring As String ' Use COM1. MSComm0.CommPort = 1 ' 9600 baud, no parity, 8 data, and 1 stop bit. MSComm0.Settings = "9600,N,8,1" ' Tell the control to read entire buffer when Input is used. MSComm0.InputLen = 0 ' Open the port. MSComm0.PortOpen = True ' Send the attention command to the modem. MSComm0.Output = "AT" & vbCr ' Ensure that the modem responds with "OK". ' Wait for data to come back to the serial port. Buffer$ = Buffer$ & MSComm0.Input MsgBox "SMS Port Open", vbOKOnly, "Port State" Else MsgBox "SMS Port Already Open", vbOKOnly, "Port State" End If End Sub '_________________________________________________ Private Sub MSComm1_OnComm() 'Attempting to Return a value from the port Select Case MSComm1.CommEvent Case "$GPGGA" 'writing the return to the buffer variable from the Comm Port Buffer = MSComm1.Input If InStr(Buffer, "$GPGGA") > 0 Then ' Converting the return so I can read it MsgBox StrConv(Buffer, vbUnicode) Case Else MsgBox "NO DEAL" End Select End Sub |
|
#13
|
|||
|