 |
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
RS232/3964R
I have to write a code in vb6 to manage a comunication between a pc and an external Euchner device using rs232/3964R line comunication.
Have some one an example of vb code to help me?
|
|
27-07-2007 at 11:49 AM |
|
|
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
Re: RS232/3964R
Tank you for your answer,
I'm able to use MSCOMM control (I'v alredy used it), my problem is use this control with 3964R specifications (determination of parity controll, command structure to send via rs 232 )
|
|
20-08-2007 at 11:05 AM |
|
|
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
Re: RS232/3964R
Attached you Will find a link to a document of my Euchner device.
I'v writen a VB6 test program but it doesn't work properly.
Euchner device accept my command string(seem to) but it doesn't give me a correct answer: Through this device i'v to read some data from a data carrier and i know what data are now stored.
In my opinion the problem is on timing gestion of comunication but i don't know where
http://www.euchner.de/download/hb/071652_e.pdf
|
|
21-08-2007 at 07:36 AM |
|
|
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
Re: RS232/3964R
I'v a problem, I don't know what kind of file this forum accept as attachment , i tried both word document and pdf document without success.
|
|
21-08-2007 at 01:34 PM |
|
|
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
Re: RS232/3964R
I tried to enclose a zip files (in attachment field) but i had this error message :
what i have to do?
Warning: Cannot modify header information - headers already sent by (output started at /home/users/web/b1459/ipw.andreavb/public_html/forum/footer_header.php:20) in /home/users/web/b1459/ipw.andreavb/public_html/forum/functions.php on line 724
Warning: Cannot modify header information - headers already sent by (output started at /home/users/web/b1459/ipw.andreavb/public_html/forum/footer_header.php:20) in /home/users/web/b1459/ipw.andreavb/public_html/forum/functions.php on line 730
Warning: Cannot modify header information - headers already sent by (output started at /home/users/web/b1459/ipw.andreavb/public_html/forum/footer_header.php:20) in /home/users/web/b1459/ipw.andreavb/public_html/forum/functions.php on line 744
Warning: Cannot modify header information - headers already sent by (output started at /home/users/web/b1459/ipw.andreavb/public_html/forum/footer_header.php:20) in /home/users/web/b1459/ipw.andreavb/public_html/forum/functions.php on line 752
ERROR!
|
|
22-08-2007 at 07:02 AM |
|
|
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
Re: RS232/3964R
The name of my file is Euchner.zip Then its name has only one dot
If you want i can paste my VB code directly on this Message box
|
|
22-08-2007 at 09:12 AM |
|
|
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
Re: RS232/3964R
The name of my zip file is Euchner.zip, then its name has only one dot.
If you want, i can paste my Vb code directly in this Message box
|
|
22-08-2007 at 09:19 AM |
|
|
admin Level: Administrator

 Registered: 04-04-2002 Posts: 530
|
Re: RS232/3964R
please try this piece of code and let me know what happens and what response do you receive (if there is one)
Option Explicit
Public DLE As String
Public STX As String
Public NAK As String
Public ETX As String
Private Sub Form_Load()
DLE = Chr(16) '10 esadecimale
STX = Chr(2)
NAK = Chr(21) '15 esadecimale
ETX = Chr(3)
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,8,1"
End Sub
Private Function SendCommand(strCommand As String) As String
Dim InBuffer As String
Dim tmp As Double
Dim i As Integer
Dim BCC As Integer
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
'send start transmission character
MSComm1.Output = STX
'loop until you receive response
tmp = Timer
Do
InBuffer = InBuffer & MSComm1.Input
If Timer - tmp > 2 Then
'wait response for 2 seconds
MsgBox "TimeOut", vbCritical
Exit Function
End If
Loop Until Left(InBuffer, 1) = DLE Or Left(InBuffer, 1) = NAK
'you received negative aknowledgement
If InBuffer = NAK Then
MsgBox "Negative Acknowledgement", vbCritical
Exit Function
End If
'OK
BCC = 0
'calculate BCC
For i = 1 To Len(strCommand)
BCC = BCC Xor Asc(Mid(strCommand, i, 1))
Next
strCommand = strCommand & DLE & ETX & Chr(BCC)
'send command
MSComm1.Output = strCommand
InBuffer = ""
tmp = Timer
Do
InBuffer = InBuffer & MSComm1.Input
Loop Until Timer - tmp > 5
'wait response for 5 seconds
SendCommand = InBuffer
End Function
Private Sub Command1_Click()
Dim strResponse As String
Dim strCommand As String
Dim strMessage As String
Dim i As Integer
'compose TL command to read from memory register 0000 - per 5 registers long
strCommand = Chr(7) & "TL" & Chr(1) & Chr(0) & Chr(0) & Chr(5)
strResponse = SendCommand(strCommand)
For i = 1 To Len(strResponse)
strMessage = strMessage & Right("00" & Hex(Asc(Mid(strResponse, i, 1))), 2) & "-"
Next
MsgBox "Response: (" & strMessage & ")", vbInformation
End Sub
|
[Edited by admin on 22-08-2007 at 02:38 PM GMT]
____________________________
AndreaVB
|
|
22-08-2007 at 01:34 PM |
|
|
admin Level: Administrator

 Registered: 04-04-2002 Posts: 530
|
Re: RS232/3964R
well, I've just checked the Euchner manual you provided and it seems to calculate the BCC using also DLE and ETX that I've added to the command after BCC calculation...
check this new code and tell me if it works
Option Explicit
Public DLE As String
Public STX As String
Public NAK As String
Public ETX As String
Private Sub Form_Load()
DLE = Chr(16) '10 esadecimale
STX = Chr(2)
NAK = Chr(21) '15 esadecimale
ETX = Chr(3)
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,8,1"
End Sub
Private Function SendCommand(strCommand As String) As String
Dim InBuffer As String
Dim tmp As Double
Dim i As Integer
Dim BCC As Integer
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
'send start transmission character
MSComm1.Output = STX
'loop until you receive response
tmp = Timer
Do
InBuffer = InBuffer & MSComm1.Input
If Timer - tmp > 2 Then
'wait response for 2 seconds
MsgBox "TimeOut", vbCritical
Exit Function
End If
Loop Until Left(InBuffer, 1) = DLE Or Left(InBuffer, 1) = NAK
'you received negative aknowledgement
If InBuffer = NAK Then
MsgBox "Negative Acknowledgement", vbCritical
Exit Function
End If
'OK
BCC = 0
'add DLE and ETX before calculating BCC
strCommand = strCommand & DLE & ETX
'calculate BCC
For i = 1 To Len(strCommand)
BCC = BCC Xor Asc(Mid(strCommand, i, 1))
Next
'add BCC to string command
strCommand = strCommand & Chr(BCC)
'send command
MSComm1.Output = strCommand
InBuffer = ""
tmp = Timer
Do
InBuffer = InBuffer & MSComm1.Input
Loop Until Timer - tmp > 5
'wait response for 5 seconds
SendCommand = InBuffer
End Function
Private Sub Command1_Click()
Dim strResponse As String
Dim strCommand As String
Dim strMessage As String
Dim i As Integer
'compose TL command to read from memory register 0000 - per 5 registers long
strCommand = Chr(7) & "TL" & Chr(1) & Chr(0) & Chr(0) & Chr(5)
strResponse = SendCommand(strCommand)
For i = 1 To Len(strResponse)
strMessage = strMessage & Right("00" & Hex(Asc(Mid(strResponse, i, 1))), 2) & "-"
Next
MsgBox "Response: (" & strMessage & ")", vbInformation
End Sub
|
____________________________
AndreaVB
|
|
23-08-2007 at 02:27 PM |
|
|
emiliana Level: Big Cheese
 Registered: 27-07-2007 Posts: 19
|
Re: RS232/3964R
Hallo,
now your code is working correctly, i have made only a little modification on the last waiting time (from 5 to 2 sec) otherwise the Euchner device doesn't receve the positive acnowledge before 2 seconds (as specificated in Euchner documentation)and it doesn't allow more other read command.
With this smal modification the VB code works very Well.
Tank you for your Help
[Edited by emiliana on 27-08-2007 at 08:51 AM GMT]
|
|
27-08-2007 at 08:50 AM |
|
|
|
|
 |
 |