borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Application Idel or not?)Next Topic (Fill Web Form fields Automatically) New Topic New Poll Post Reply
AndreaVB Forum : VB General : RS232/3964R Solved Topic
Poster Message
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

to handle 232 communication with VB you need to use the MSCOMM control. you can search the site for MSCOMM Control and you'll find some hints about how to use it...

you can follow some of the topics related to serial communication

here are some:

http://www.andreavb.com/forum/viewtopic.php?TopicID=4281

http://www.andreavb.com/forum/viewtopic.php?TopicID=2314

hope this helps

____________________________
AndreaVB

20-08-2007 at 09:08 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

what are these specifications? do you have a link? is it a special protocol definition?

____________________________
AndreaVB

20-08-2007 at 02:40 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

It would be interesting to see your piece of code for communicating and what you receive and what you expected to receive...

[Edited by admin on 21-08-2007 at 09:11 AM GMT]

____________________________
AndreaVB

21-08-2007 at 07:41 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

you can attach them as zip files. Use Winzip to create the archive!

    

____________________________
AndreaVB

21-08-2007 at 03:14 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

I've checked and it may happen if the file name you are trying to upload contains more than one dot (name from extension separator). I tested it uploading a file named "test1.1.0.zip": this causes the error. I'll try to fix it, meantime try to upload a file name with only one dot at the end of the file name before the extension (.zip)

____________________________
AndreaVB

22-08-2007 at 08:32 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

OK, there was another error in the scripts, I've had to reset the permission of the upload directory...hope it works fine now...thanks for the feedback!!

____________________________
AndreaVB

22-08-2007 at 09:09 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

try to upload it, I've fixed a bug in the upload script! let me know

    

____________________________
AndreaVB

22-08-2007 at 09:14 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

Do as you like: you can post the code in your message or upload the file. I've corrected a bug that was not related to dot, there was an error with folder permissions for uploaded files!!...so now you should be able to upload a zip file!!

____________________________
AndreaVB

22-08-2007 at 09:23 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon Re: RS232/3964R

Here there are my zip files

____________________________
Attached:
Euchner.zip 17 KB (Downloads: 3)

22-08-2007 at 10:23 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon Re: RS232/3964R

I have tried your code and it doesn't work correctly:
1) on my Euchner device there's a led that
    mean "command received": this led never light on during
    the read cycle ( in my code light up as soon as Vb code  
    send the read request string)
2) at the end of reading cycle I have a NAK response from
    Euchner device (code15 Hex in the messages box)

23-08-2007 at 11:13 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon Re: RS232/3964R

I' have tried your last code and the result are:
Now my Euchner device accept the read command ( onboard led switch on) but its answere in not yet what i want.
The Euchner response is 10-02-02-02- .
I tally ho that if I modify the wait response, for example from 5 sec to 15 sec, also the answer change:
10-02-02-02-02-02-02-.
I have the same behaviour in my code

24-08-2007 at 06:41 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: RS232/3964R

ok, it seems that it is waiting for a DLE character to start sending back te response...try this:


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 = ""
    'wait for DLE and STX
    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,2)=DLE & STX
    InBuffer=""
    'Send DLE
    MSComm1.Output = DLE
    tmp = Timer
    Do
        InBuffer = InBuffer & MSComm1.Input
    Loop Until Timer - tmp > 5
    'wait response for 5 seconds
    SendCommand = InBuffer
    'Send DLE after receving message
    MSComm1.Output = DLE
End Function


tell me what do you receive this time

____________________________
AndreaVB

24-08-2007 at 07:56 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
emiliana
Level: Big Cheese

Registered: 27-07-2007
Posts: 19
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : RS232/3964R Solved Topic
Previous Topic (Application Idel or not?)Next Topic (Fill Web Form fields Automatically) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder