![]() |
| The AccuTerm forum has moved. Go to community.rocketsoftware.com to register for the new Rocket forum. |
|
Post Reply
|
| Author | |
rsine
Groupie
Joined: May 18 2007 Status: Offline Points: 72 |
Post Options
Thanks(0)
Quote Reply
Topic: How do I read data from a PC serial/USB port?Posted: October 03 2007 at 5:24am |
|
I need to connect a shipping scale to either the serial or USB port of a windows PC. How can I read the data from the scale within a Pick application using Accuterm 2K2? |
|
![]() |
|
PSchellenbach
Admin Group
Moderator Joined: December 15 2003 Location: United States Status: Offline Points: 2150 |
Post Options
Thanks(0)
Quote Reply
Posted: October 04 2007 at 4:20am |
|
Hi Rsine -
Here's a link to a topic that describes how to set up a second AccuTerm session that connects to a serial device (scale). Thanks, Pete |
|
![]() |
|
rsine
Groupie
Joined: May 18 2007 Status: Offline Points: 72 |
Post Options
Thanks(0)
Quote Reply
Posted: October 04 2007 at 4:32am |
|
Thanks Pete. This seems to be exactly what I am looking for. One question I have is about the second session. I would like to start the session when retrieving information from the scale and stop it after the information is retrieved but not let the user know there is a second session running. Is this possible?
|
|
![]() |
|
George_Smith
Groupie
Joined: April 09 2004 Location: United States Status: Offline Points: 41 |
Post Options
Thanks(0)
Quote Reply
Posted: October 04 2007 at 4:46am |
|
I'd be very interested to see your final script. I had a similar application (interfacing to a serial audiometer rather than a scale, but same idea) but I couldn't figure out how to use the bi-dir script.
In the end, I wrote a program in visual foxpro that grabbed the received data from a hidden accuterm session. A bit kludgy, but it's worked solidly since it went in in May. I always had the sense there should be a nice self contained accuterm solution. |
|
![]() |
|
rsine
Groupie
Joined: May 18 2007 Status: Offline Points: 72 |
Post Options
Thanks(0)
Quote Reply
Posted: October 18 2007 at 6:32am |
|
Pete, I know this is a real newbie question but how do I capture the data coming from the slave session? I tried using an INPUT but that did not seem to work.
|
|
![]() |
|
PSchellenbach
Admin Group
Moderator Joined: December 15 2003 Location: United States Status: Offline Points: 2150 |
Post Options
Thanks(0)
Quote Reply
Posted: October 18 2007 at 1:23pm |
|
Hi rsine -
If your external device sends a CR after its data, INPUT should work fine. If it does not, you probably need to use IN or other single-character input function that your platform supports. Thanks, Pete |
|
![]() |
|
rsine
Groupie
Joined: May 18 2007 Status: Offline Points: 72 |
Post Options
Thanks(0)
Quote Reply
Posted: October 19 2007 at 4:28am |
|
Pete, Another question I have is the setup for the slave session. Is there anything special I should do? Using a port monitor on the session, I see the following:
0.00006453 Atwin2k2.exe IRP_MJ_CREATE Serial0 SUCCESS Options: Open
0.00000307 Atwin2k2.exe IOCTL_SERIAL_SET_QUEUE_SIZE Serial0 SUCCESS InSize: 4096 OutSize: 2048 0.00000223 Atwin2k2.exe IOCTL_SERIAL_GET_BAUD_RATE Serial0 SUCCESS 0.00000196 Atwin2k2.exe IOCTL_SERIAL_GET_LINE_CONTROL Serial0 SUCCESS 0.00000196 Atwin2k2.exe IOCTL_SERIAL_GET_CHARS Serial0 SUCCESS 0.00000196 Atwin2k2.exe IOCTL_SERIAL_GET_HANDFLOW Serial0 SUCCESS 0.00001229 Atwin2k2.exe IOCTL_SERIAL_SET_BAUD_RATE Serial0 SUCCESS Rate: 9600 0.00000615 Atwin2k2.exe IOCTL_SERIAL_SET_RTS Serial0 SUCCESS 0.00000615 Atwin2k2.exe IOCTL_SERIAL_SET_DTR Serial0 SUCCESS 0.00000391 Atwin2k2.exe IOCTL_SERIAL_SET_LINE_CONTROL Serial0 SUCCESS StopBits: 1 Parity: ODD WordLength: 7 0.00000223 Atwin2k2.exe IOCTL_SERIAL_SET_CHAR Serial0 SUCCESS EOF:1a ERR:7e BRK:7e EVT:0 XON:11 XOFF:13 0.00000419 Atwin2k2.exe IOCTL_SERIAL_SET_HANDFLOW Serial0 SUCCESS Shake:80000001 Replace:80000042 XonLimit:1024 XoffLimit:1024 0.00000196 Atwin2k2.exe IOCTL_SERIAL_SET_TIMEOUTS Serial0 SUCCESS RI:-1 RM:0 RC:0 WM:0 WC:100 0.00000363 Atwin2k2.exe IOCTL_SERIAL_PURGE Serial0 SUCCESS Purge: TXABORT RXABORT TXCLEAR RXCLEAR 0.00000419 Atwin2k2.exe IOCTL_SERIAL_GET_MODEMSTATUS Serial0 SUCCESS 0.00000279 Atwin2k2.exe IOCTL_SERIAL_SET_TIMEOUTS Serial0 SUCCESS RI:-1 RM:0 RC:0 WM:0 WC:100 0.00000307 Atwin2k2.exe IRP_MJ_READ Serial0 SUCCESS Length 0: 0.00000391 Atwin2k2.exe IOCTL_SERIAL_GET_MODEMSTATUS Serial0 SUCCESS 0.00000307 Atwin2k2.exe IOCTL_SERIAL_SET_TIMEOUTS Serial0 SUCCESS RI:-1 RM:0 RC:0 WM:0 WC:100 0.00000475 Atwin2k2.exe IRP_MJ_READ Serial0 SUCCESS Length 0: 0.00000503 Atwin2k2.exe IOCTL_SERIAL_GET_MODEMSTATUS Serial0 SUCCESS The IRP_MJ_READ having a length of 0 is what I am not understanding. I monitored the port on another scale connected to a UPS Worldship PC and the comm data looks like this:
0 0.00008760 WorldShipTD.exe IRP_MJ_CREATE Serial0 SUCCESS Options: Overwrite 1 0.00000437 WorldShipTD.exe IOCTL_SERIAL_GET_BAUD_RATE Serial0 SUCCESS 2 0.00000131 WorldShipTD.exe IOCTL_SERIAL_GET_LINE_CONTROL Serial0 SUCCESS 3 0.00000111 WorldShipTD.exe IOCTL_SERIAL_GET_CHARS Serial0 SUCCESS 4 0.00000115 WorldShipTD.exe IOCTL_SERIAL_GET_HANDFLOW Serial0 SUCCESS 5 0.00001333 WorldShipTD.exe IOCTL_SERIAL_SET_BAUD_RATE Serial0 SUCCESS Rate: 9600 6 0.00000585 WorldShipTD.exe IOCTL_SERIAL_SET_RTS Serial0 SUCCESS 7 0.00000570 WorldShipTD.exe IOCTL_SERIAL_SET_DTR Serial0 SUCCESS 8 0.00000340 WorldShipTD.exe IOCTL_SERIAL_SET_LINE_CONTROL Serial0 SUCCESS StopBits: ERROR Parity: ODD WordLength: 7 9 0.00000126 WorldShipTD.exe IOCTL_SERIAL_SET_CHAR Serial0 SUCCESS EOF:0 ERR:0 BRK:0 EVT:0 XON:0 XOFF:0 10 0.00000390 WorldShipTD.exe IOCTL_SERIAL_SET_HANDFLOW Serial0 SUCCESS Shake:1 Replace:40 XonLimit:0 XoffLimit:0 11 0.00002675 WorldShipTD.exe IOCTL_SERIAL_IMMEDIATE_CHAR Serial0 SUCCESS Char: d 12 0.00000532 WorldShipTD.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS 13 0.00000458 WorldShipTD.exe IRP_MJ_READ Serial0 SUCCESS Length 18: 0.00 lb GR ... 14 0.00003793 WorldShipTD.exe IOCTL_SERIAL_IMMEDIATE_CHAR Serial0 SUCCESS Char: d 15 0.00000592 WorldShipTD.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS 16 0.00000527 WorldShipTD.exe IRP_MJ_READ Serial0 SUCCESS Length 18: 0.00 lb GR ... 17 0.00002299 WorldShipTD.exe IOCTL_SERIAL_IMMEDIATE_CHAR Serial0 SUCCESS Char: d 18 0.00000543 WorldShipTD.exe IOCTL_SERIAL_GET_COMMSTATUS Serial0 SUCCESS 19 0.00000491 WorldShipTD.exe IRP_MJ_READ Serial0 SUCCESS Length 18: 0.00 lb GR ... The length is 18. This is very new to me. So if anybody has this working and can share their code, I would be grateful. |
|
![]() |
|
rsine
Groupie
Joined: May 18 2007 Status: Offline Points: 72 |
Post Options
Thanks(0)
Quote Reply
Posted: October 19 2007 at 5:47am |
|
I may have been barking up the wrong tree. After all the effort used doing the port monitoring, I found that if I simply press the <enter> key on the slave session, the weight is returned from the scale. My question is now how do I use this new found knowledge to get the main session to retrieve the data from the slave session?
|
|
![]() |
|
rsine
Groupie
Joined: May 18 2007 Status: Offline Points: 72 |
Post Options
Thanks(0)
Quote Reply
Posted: October 19 2007 at 5:59am |
|
I figured out the answer to my own question on how to send an <enter> key to the slave session. The solution was to add the following line prior to entering the loop monitoring the slave session:
s2.Output(Chr$(13))
|
|
![]() |
|
rsine
Groupie
Joined: May 18 2007 Status: Offline Points: 72 |
Post Options
Thanks(0)
Quote Reply
Posted: October 24 2007 at 2:43am |
|
George,
Below is the script I have gotten to work. Hopefully it will help you and others that are trying to do the same thing.
Sub Main()
'Script to read data from a Fairbanks scale.
Dim Txt As String
Dim Can As String Dim N As Integer Dim s1 As Session Dim s2 As Session Dim ScaleSessionIndex As Integer
'Save the hwnd for the session that executed the script because once the new session is
'added, it will become the current active session. ThisActiveSession = ActiveSession.hwnd 'Add a new session but keep it hidden
AccuTerm.Sessions.Add("C:\Program Files\Atwin\Scale.atcf",-1,1,1) 'The index for the scale session should be the most recently added
ScaleSessionIndex = Sessions.Count - 1 'If the scale session is the only session running, error out of the script
If ScaleSessionIndex = 0 Then MsgBox("There has to be at least 1 main session open for scale to work",vbInformation,"Scale Error") Exit Sub End If 'Determine the index value of the session that executed the script. This is needed in case multiple sessions are
'running. If there are, you cannot guarantee that index value 0 was the executing session. For x = 0 To ScaleSessionIndex If ThisActiveSession = Sessions(x).hwnd Then Exit For End If Next x Set s1 = Sessions(x) Set s2 = Sessions(ScaleSessionIndex) s1.InputMode = 1
s2.InputMode = 1 'quit when this character is received. This may be unique to the
'model of scale being used or could be universal. Tweak as necessary. Can = Chr$(4) 'A carriage return prompts the scale session to retrieve data from the scale. This may be unique to the
'model of scale being used or could be universal. Tweak as necessary. s2.Output(Chr$(13)) 'Read the data returned from the scale session and send it back to the session that executed the
'script. Do Txt = s2.Input(0, 80, 0)
N = InStr(Txt, Can)
If N Then s1.Output Left$(Txt, N-1) Exit Do Else s1.Output Txt End If Loop
s1.InputMode = 0 s2.InputMode = 0 'End the scale session because it is no longer needed s2.Terminate End Sub |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |