[ASK] Programming for LED Display Board with RS422 connection

mr_jj

Member
Join Date
Feb 2008
Location
Jakarta
Posts
3
Dear All,

I need help.

I am new here & I don't know whether i join the right forum or not for asking this thing.

My company bought a 2nd-hand LED Display Board with 2 lines of LED display (each 16 digits). We are going to reprogram the software by using Visual Basic 6. We have tried it several times, but it's still not work.

This is some codes that was given to me.
Serial Protocol (serial com: RS422 9600 bps, 8 data bits, 1 stop bit, no parity).

LED LINE 1:
<STX> <0xFF> <Address Byte> <0x80> <0x90> <'P'> <'1'> <16 Alphanumeric characters to be display (including commas)> <0x80> <ETX> where Address Byte is 0x81 (both Boards). STX is 0x02 and ETX is 0x03. E.g. Transmit: [0x02 0xFF 0x81 0x80 0x90 0x50 0x31 0x55 0x53 0x44 0x31 0x2C 0x30 0x30 0x30 0x2C 0x30 0x30 0x30 0x2C 0x30 0x30 0x30 0x80 0x03] to show 'USD1,000,000,000' as Price 1 on LED Board.

LED LINE 2:
<STX> <0xFF> <Address Byte> <0x80> <0x90> <'P'> <'2'> <16 Alphanumeric characters to be display (including commas)> <0x80> <ETX> where Address Byte is 0x81 (both Boards). STX is 0x02 and ETX is 0x03. E.g. Transmit: [0x02 0xFF 0x81 0x80 0x90 0x50 0x32 0x55 0x53 0x44 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x35 0x2C 0x30 0x30 0x30 0x80 0x03] to show 'USD 5,000' as Price 2 on LED Board.

Those are the codes was given to me.

We trying to use the VB component called "MSCOMM" for the coding, but it is still not work.

Does anybody understand how to write the right code by using VB6 to communicate with the LED Display Board?

Thanks before for the help.
 
I've done a bit of serial work with VB6. (For those who aren't aware, VB6 was the last VB version that included both serial port access and the ability to create stand-alone programs.)

It's been a few years since I've had the priviledge, so bear with me.

Make sure you do the following:

1. Ensure that your port is RS-422 capable.
2. Open the port with MSComm1.Open
3. Make sure there's an appropriate delay between the commands. Your computer will be running at a much faster speed than the serial device, so you might have to put in something like

Sleep(20)

to get the PC to sleep for 20 ms between words.

3. Get a serial port monitoring program and make sure you're putting the right things out on the port.

Throw up your code and let's see what can be fixed up.
 
Hi All,

Thanks for your support & answers.

RS422 support --> Yes, it is.

Below are some codes that we've tried to write for testing, but it still not working. Here it is:

-----------
Private Sub Command1_Click()
MSComm1.Output = Text1.Text
End Sub

Private Sub Form_Load()
MSComm1.RThreshold = 1
MSComm1.RTSEnable = True
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
Text1.Text = Clear
Text2.Text = Clear
End Sub


Private Sub MSComm1_OnComm()
c = MSComm1.Input
Text2.Text = Text2.Text & c
End Sub
-----------

Do I write a wrong codes for it? Please advice. Thanks a lot.
 
I don't think that you can just pass a string to the MSComm output. I'm almost certain that you have to put the bytes in one at a time.

I can't look at code that works for sure since it's been two years since I've worked at the place where I wrote the code. I don't have VB installed on this machine. If I had a compiler and an RS-232 device for checking, I could promise you something.

A few tips:

Option Explicit 'This is VITAL to any VB6 code.

You might have to break the string into bytes and then write each byte by itself. That's what I had to do an a real low-level device with no room for an interface. As mentioned before, you might have to convert to Asc() values.
 
Serial communication in VB is childs play.

MSCOMM will easily handle 9600 bps, 8 data bits, 1 stop bit, no parity. if your PC has RS232 you just need to use RS232 to R422 converter. Optionally you can install card with serial ports.

Before you kill yourself with programming, test if you can communicate with the target device using some sort of terminal (hyperterminal will do but you may pick something like SuperMon,
you get v5.5 here: http://forums.mrplc.com/index.php?dlcategory=48)

This will confirm if your port is available, cables are correct and if the message you try to send is accepted by target device.

If that works (manually sending message) then we can automate it with some program, VB will do just fine.

Start new project, Standard executable.
Click Ctrl+T to open components and select "Microsoft Comm Control 6.0" (place check mark in front of it and click ok)

This will add new icon in your tool pallet (it will look like phone). Double-click on it and you will also see it on the form.

while we are placing controls on form, also drop one button and two text boxes.

double-click on MSComm control that is on your form
and in code window add line:

Me.Text1.Text = MSComm1.Input

This will put in Text1 whatever is received through serial port.

doubleclick on command1 button and enter code that will open/close serial connection (in this case it's COM1 but you can change that, right?):

If MSComm1.PortOpen Then
Me.Caption = "Offline"
MSComm1.PortOpen = False
Else
MSComm1.ComPort =1 'whatever port you have
MSComm1.Settings = "9600,n,8,1"
Me.Caption = "Online"
MSComm1.PortOpen = True
End If

doubleclick on command2 button and enter code that allows us to send data:

MSComm1.Output = Me.Text2.Text & vbCrLf

Go back to form and click once on MSComm then go to properties and change RTreshhold from 0 to 1

Run it...

this is complete code, writen and tested in last 10 minutes:

 
Private Sub Command1_Click() 'open/close port
If MSComm1.PortOpen Then
Me.Caption = "Offline"
MSComm1.PortOpen = False
Else
MSComm1.CommPort = 1 ' using port COM1...
MSComm1.Settings = "9600,n,8,1"
Me.Caption = "Online"
MSComm1.PortOpen = True
End If
End Sub
Private Sub Command2_Click() 'send data
MSComm1.Output = Me.Text2.Text & vbCrLf
End Sub

Private Sub MSComm1_OnComm() 'receive data
Me.Text1.Text = Me.Text1.Text & MSComm1.Input
End Sub


 
forgot screenshots...

VB6_terminal_form.jpg


VB6_terminal.jpg
 
and try replacing send command to:


 
MSComm1.Output = Asc(2) & Asc(255) & Asc(128) & Asc(129) & Asc(144) & "P1" & Mid(Me.Text2.Text, 1, 16) & Asc(128) & (3)



or you can pass it as variable

Dim temp as string
temp = Asc(2) & Asc(255) & Asc(128) & Asc(129) & Asc(144) & "P1" & Mid(Me.Text2.Text, 1, 16) & Asc(128) & (3)
MSComm1.Output = temp

you DON'T have to or want to write code that will send it byte by byte, this is what port hardware does. Program merely configures port hardware and places data into it's buffer...
 
Last edited:
When doing ASCII / Serial port comm from a PC, there are many ways to get in trouble. I have found that it is very useful to use a second PC running "Terminal.exe" from an old OS like Win95.

"Terminal.exe is a free standing terminal program from Microsoft that has programmable function keys built in. You can define a whole series of strings and then click the "key" on the screen and the string comes out the port.

I would break the job into two sepreate parts. First, work with "Terminal" and your RS422 converter until you can identify a properly defined string which shows up on the display. Once you can see what you want, then design your VB app to send the string. If this is a problem, drop back to RS232 and use a second PC with "Terminal" to show you the ASCII string that VB is sending. Once the two match, then bring them all together.

In case you are not aware, the RS422 is just a 0 - 20 mA current to replace the voltage based signal in the RS232. So pin 2 & 3 in the 232 side become a 20 mA current in the 422 loops which gives you lower impedance and longer distance.

All you have to do to get RS422 for your display is to use a short haul modem. You can find small inexpensive ones that are powered by your serial port that usually work fine.

Note: Some RS232 ports are capable of sourcing the 422 currents, if connected correctly, but I'm not into swimming upstream.

Best Regards,

Bob A.
 
no, don't connect them directly. use converter. signals levels are different between RS232 and RS422...
(later one uses differential signal, not current)
just drop in small $40 converter like from B&B Electronics etc (check www.RS485.com)
 
Last edited:
on second tought, there is still one small error. the 16-character message should be fixed length so


MSComm1.Output = Asc(2) & Asc(255) & Asc(128) & Asc(129) & Asc(144) & "P1" & Mid(Me.Text2.Text, 1, 16) & Asc(128) & (3)



should be changed to

MSComm1.Output = Asc(2) & Asc(255) & Asc(128) & Asc(129) & Asc(144) & "P1" & Mid(Me.Text2.Text & "                ", 1, 16) & Asc(128) & (3)




If the content of the text box is short, this will fill up the remaining places (up to 16 characters) with spaces. good luck...
 

Similar Topics

Hi everyone! I've started to learn PLC programming (Simatic manager with plcsim (siemens s7 300). I read an interesting lesson on the internet...
Replies
5
Views
2,970
I know C language. I want to make a logic program and then convert it to PLC program. Is it possible to do that? How?----Thanks a lot!
Replies
10
Views
2,883
I have a program that I've used 100 times. SQO settings: File N7:0, Mask 0FFFFh, Dest B3:1, Control R6:0, Length 8, Pos 2. Length & Position...
Replies
48
Views
792
We are to develop a first application in Codesys. It will contain motion (Softmotion) with drives on Ethercat (CSP mode). Off course there will be...
Replies
2
Views
835
Hi. Rockwell learning curve 132-1b. I was having trouble to change IP address on a EN2TR. Finally found out that I need to change the IP...
Replies
1
Views
734
Back
Top Bottom