Results 1 to 15 of 15

Thread: C# with RS485/Serial Port Communication

  1. #1

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    C# with RS485/Serial Port Communication

    I have to work with a device that uses RS485 protocol to talk to a PC. So there are two things I need to get done:

    1. Use an RS485 connector to connect the device to my PC. But I don't have an RS485 port on my machine. On checking the internet I found I could use a bridge to convert RS485 to RS232 and back. Supposing that's the way I have to go, will it impact the communication with the device in any way? Will I then have to code the app to use RS232?

    2. Secondly, are there any good samples out there which use serial communication with C#?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: C# with RS485/Serial Port Communication

    Quote Originally Posted by honeybee View Post
    I have to work with a device that uses RS485 protocol to talk to a PC. So there are two things I need to get done:

    1. Use an RS485 connector to connect the device to my PC. But I don't have an RS485 port on my machine. On checking the internet I found I could use a bridge to convert RS485 to RS232 and back. Supposing that's the way I have to go, will it impact the communication with the device in any way? Will I then have to code the app to use RS232?

    2. Secondly, are there any good samples out there which use serial communication with C#?

    .
    If you want to connect it to the RS232 port on your computer then you can get small self powered adapters - RS232 9pin one one with the RS422/485 screw terminals on the other. Cost maybe $20

    Or you can use a USB adapter. That has USB on one end with 422/485 on the other.

    I mention 422 and 485 because electrically they're pretty much the same thing except we usually use RS422 as a point-to-point to connect two devices to each other wherease Rs485 is usually a multidrop protocol based thing where you have a controller that 'polls' a number of slave devices all sharing the same bit of wire.

    So, if you are using RS485 then not only do you need to think about the hardware you'll probably also need to look the RS485 protocol which can be a problem because there is no actual industry standard protocol. If you have an RS485 device then you need to be looking at the supplier of that device to find out if it's 2 wire or 4 wire RS485 AND also information about the protocol.

    But, step back a bit, and you may find that the supplier of the RS485 device also supplies the computer hardware with built in RS485 protocol and all you need to do is send receive RS232 data.

    It is a big subject with too many variable to give much advice. Talk to the supplier of the other 485 devices.

    As for sample code that uses c# you can see some at

    http://www.comm64.com

    but that's just going to show you RS232 but it's a start I suppose.

  3. #3

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: C# with RS485/Serial Port Communication

    That's a very good reply, thanks !

    The device I am talking about is a finger vein reading machine from Hitachi. We have the manual which explains the different commands to be sent to the device and the responses to each of those commands that the device will send back. On top of that, the whole thing works pretty much along the lines of what you described: keep polling the device. I didn't know you could connect multiple devices through the RS485. Does it mean I could attach multiple finger vein scanners through a single RS485 connector to a PC and manipulate them all together?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  4. #4

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: C# with RS485/Serial Port Communication

    Can anyone help me with a circuit diagram or equivalent of an RS485 connector? I have to connect the cables coming out of the device to an RS485 connector which will then be plugged into my PC.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5
    Addicted Member
    Join Date
    May 2004
    Posts
    141

    Re: C# with RS485/Serial Port Communication

    TX+ to RX+
    TX- to RX-
    Last edited by Axcontrols; Jan 12th, 2011 at 03:52 PM.

  6. #6
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: C# with RS485/Serial Port Communication

    let me explain something I mentioned in my previous post. I mentioned 2 wire and 4 wire RS485 and also mentioned RS422.

    RS422 and RS485 are electronically very similar.

    If you look at an RS232 pinout you'l see that there's one pin for TransmitData (TX) and another for ReceiveData (RX). The signal levels can be between -12 and +12 volts measured against signal ground. So, the minimum number of wires that RS232 requires is 3. They are TX, RX and GND

    The problem with RS232 is that over longer distances you get voltage drop as well as interference.

    RS422 does not use a GND at all. The TX is actually 2 wires. TX+ and TX- and the RX is also 2 wires RX+ and RX-. RS422 also allows full hardware flow control in which case there's also RTS+ and RTS- and CTS+ and CTS- and as you can imagine the whole thing can require quite a few wire although as a minimum to just carry the RX and TX you'd need 4 wires.

    The signal levels are between +3 and -3 volts. These two wires are twisted around each other (twisted pair) so that any interference affects both wires equally so if there was a sudden voltage swing they'd both spike up or down together and the difference between the two wires (differential signal) remains constant and therefore reliable. Consequentially RS422 can be used over 1000 meters. Much further than RS232.

    Using those 4 wires. TX+ TX- RX+ and RX- you can connect more than one device to the same wires in a kind of network. Any message sent by one device would be received by all other devices. Picture the message display system in an airport where they all simply display the same data which is being broadcast from a master device. Obviously if any of those slave devices needed to send a message back to the master then the master wouldn't know which device was talking also the master wouldn't have any way to send a message to just one specific display.

    So, if you added an ID of some description to the start of each message you can say which device the message is for. As soon as you do this you have a protocol and suddenly we're talking about RS485.

    The protocol would require a packet of data that contains a device ID. The master device sends a poll command to a specific device. All devices on the network will hear that poll command (allowing you to broadcast something such as updating all the displays in an airport with the lastest cancellation information. But by using the ID only the relevant device will reply and the master and slave can talk to each other while other devices ignore the conversation.

    So yes, you could connect more than one device to the wire as long as the protocol specifies a device ID. If the protocol does not contain a device ID then you'd have no way of talking directly to one device or know which device was talking to you.

    you asked about connections.

    RS232 is quite strict about which pins are used for the various signals. But there is no such standard for RS422 or RS485 Lots of hardware just uses screw terminals. Some will use the same kind of connection as an RS232 port, perhaps a different gender, and the supplier of that hardware will tell you what pin carries what signal.

    So far I've described 4 wire RS485. There is also a thing called 2 wire RS485. This is where TX+ and RX+ share the same wire. As does TX- and RX- so you only need two wires.

    The master enables it's transmitter, sends the poll command and immediately switches off its transmitter allowing the slave device to reply down the same wire. This quick power on/off is what we refer to as 'Turn Round Time'. It's not complicated but for the uninitiated the turn round timing can be quite difficult to do the first time you make your own 2 wire 485 protocol. Using 4 wire 485 is much easier.

    If your computer has 4 wire 485 and your external device has 2 wire then you can still make a connection but I won't go there unless you need to. Do you ?

    Unfortunately I can't give you much help regarding your specific application because, as I said, RS485 is not such a strict standard as RS232 but I hope i've given you something to work with.

  7. #7

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: C# with RS485/Serial Port Communication

    Hello IanS, that's a beautiful explanation.

    I have already posted the details of the device wires on the other thread, but because your explanation here is an excellent one, I shall continue the discussion on this thread itself. Here's the link to the post which shows the labels attached to each of the wires coming out of the device:

    http://www.vbforums.com/showpost.php...88&postcount=6

    Yep, the wires are labelled:

    1. FG
    2. TX/RX-
    3. TX/RX+
    4. VP (DC24V)
    5. VG
    6. FG
    I shall also attach some pictures in the next post to help explain what hardware I have.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  8. #8

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: C# with RS485/Serial Port Communication

    I have attached three images here:

    1. xx005 is the wires coming out of the device connector. They are all labelled.
    2. xx011 is the serial connector we are planning to use. It's a 9-pin male connector on one side and a 9-pin female and a 25-pin female connector on the other side. The image shows the other side, with both the female connectors.
    3. xx013 is the wires at the 9-pin male connector labelled 1 to 9.

    Questions:

    1. Can I connect the wires from xx005 to the wires in xx013 directly, or do I need another connector to go between them?
    2. Which wires from xx005 will connect to which wires from xx013?

    .
    Attached Images Attached Images    
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  9. #9

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: C# with RS485/Serial Port Communication

    Quote Originally Posted by dilettante View Post
    FG may be "foil ground" (shielded twisted-pair cable). VP may be a supply voltage to power the device (?) and perhaps VG is the power and signal reference ground (?). Are you sure one of those FGs isn't SG (signal ground)?

    Half-duplex RS-485 is often used as a bus connector, implying the device may require a special protocol for operation.
    Thanks for the post, Dilettante. Since I shall be following up on the matter on this thread itself, please continue reading here and posting your comments here.

    The wire numbered #1 should be the signal ground, as indicated in the Japanese manual.

    Regarding the protocol, the device does specify a protocol to be used when communicating. However till it is connected to the PC, it would be pretty much useless. Which brings me to another important question: Now that I have a serial device which is not yet connected to the PC, can I simulate this device and program against it? Similar to what mock objects are used for in the TD programming?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  10. #10
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: C# with RS485/Serial Port Communication

    FG is probably frame ground. That's used for shielding.

    RS485 does not need or use signal or reference ground. That's the beauty and the long distance reliability of RS485. It's a simple differential signal between TX+ and TX-

    Looking at those pinouts I can see that you have a 2 wire RS485. As dilletante said the 24v is probably there to power up the external device. That obviously is not going to be powered by a PC's serial port. That's where you're going to connect a power supply to power up the device and VG is probably the 0v for the power supply.

    So, the TX and RX are the communications.

    FG is frame ground. That's shield against interference. For a short cable probably not required. For a long cable connect that to the chassis of the device (0v)

    VP is the 24vpower supply
    VG is the other wire, 0v of the power supply.

    The fact it's 2 wire RS485 does mean that you have to use the same pair of wires for sending as well as receiving so the protocol is a little more complicated.

    Even though I do this all the time I'd still be in touch with the supplier of that device. You're not the first person to use that device so there is bound to be something somewhere you can download if you search for it.

    If you really are stuck and don't have any assistance at all then I'll see if I can assist - but I'm off out now - I'll read more this evening.

    Ian

  11. #11

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: C# with RS485/Serial Port Communication

    Well, I am indeed stuck, though after searching for info on the net and after reading your posts, I guess I shall be getting out of the sticky situation soon.

    So the wires 4 and 5 of the device will go to the power supply.
    I shall leave wire 6 as it is for now, since the cable will hardly be 2ft.
    Wires 1, 2 and 3 are what will make up the data part. Where do I connect these to the serial wires?

    I have attached the diagram of a 9-pin serial connector.

    Pin 2 is for Receive data, while pin 3 is for Transmit. Which of these is connected to wire 2, and which is connected to wire 3?

    Unfortunately I don't have time to contact the manufacturer and wait for their help on this matter, so if you can help me out, it would be GREAT. I have been near frustration as I have zero knowledge of electrical or electronic engineering.

    .
    Attached Images Attached Images  
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  12. #12
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: C# with RS485/Serial Port Communication

    RS232 works with different signal levels then RS485. You can't connect them direct to the bus. A piece of hardware is needed between them. On the rs232 side a max232 for example and on the rs485 side a max485. Otherwise buy a out of the box solution as a kit in a local electronic store. Those RS485 chips do need a ground connection connected with each other.
    Also look at the communication properties/protocol like baudrate etc if your com port can handle those things. Often is bit7 used for special purposes like address resolution wich can be a pain in the a..... for working under Visual Studio.
    What I mean is look at these things first if you fully understand this before spending money/time in hardware.

  13. #13

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: C# with RS485/Serial Port Communication

    Here's an update:

    I have downloaded a software called Docklight (v1.9 evaluation) which sends data on the serial port and listens back for any response. I tested the software as well as the serial port by performing a simple loopback test. Ready to go.

    Wires 1 (SG) and 4 (24vDC) went to a 24v DC power supply and the device powered on. The LED blinked and on trying to operate the device the buzzer sounded. So the device is now powered on.

    We got a connector that has a serial cable coming out from one end and three holes on the other. These three holes are supposedly for the TX/RX and Ground wires for the RS485 device. The TX/RX+ and TX/RX- wires go into two of the hole, while a third Ground wire was inserted in the remaining hole. The connector was connected to the PC serial port. I ran Docklight and sent a few messages to the serial port. But it returned some junk. I tried swapping the TX/RX+ and TX/RX- wires too, but the result remains junk. Sometimes the serial port is flooded with junk characters and the application hangs.

    We got another connector, a rectangular white box which is a proper RS232/USB to RS485 connector. It has a power supply pin, a serial female port and a mini-USB port on one side, and a serial male port (marked as RS485) and two jacks on the other side. I now connected the remaining wires (except the two sent to the power supply) to the same numbered wires on the serial cable, and put the serial cable into the RS485 port of the connector. Now the device is connected to the connector on the RS485 port. From the other end, a serial cable runs from the connector to the PC.

    Now when I try to send anything to the serial port, there's no response. After repeatedly trying for some time, I finally plugged out the device from the connector and connected it directly to the serial port of the PC. Now when I send anything to the serial port, it performs a loopback! Surprised at this, I tried swapping the #2 and #3 wires (TX/RX+ and TX/RX-) but the result is the same, it only does a loopback.

    I am in a fix now. Can anyone show me the correct way to wire up this device?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  14. #14
    New Member
    Join Date
    Jun 2011
    Posts
    1

    Re: C# with RS485/Serial Port Communication

    Quote Originally Posted by IanS View Post
    If you want to connect it to the RS232 port on your computer then you can get small self powered adapters - RS232 9pin one one with the RS422/485 screw terminals on the other. Cost maybe $20

    Or you can use a USB adapter. That has USB on one end with 422/485 on the other.

    I mention 422 and 485 because electrically they're pretty much the same thing except we usually use RS422 as a point-to-point to connect two devices to each other wherease Rs485 is usually a multidrop protocol based thing where you have a controller that 'polls' a number of slave devices all sharing the same bit of wire.

    So, if you are using RS485 then not only do you need to think about the hardware you'll probably also need to look the RS485 protocol which can be a problem because there is no actual industry standard protocol. If you have an RS485 device then you need to be looking at the supplier of that device to find out if it's 2 wire or 4 wire RS485 AND also information about the protocol.

    But, step back a bit, and you may find that the supplier of the RS485 device also supplies the computer hardware with built in RS485 protocol and all you need to do is send receive RS232 data.

    It is a big subject with too many variable to give much advice. Talk to the supplier of the other 485 devices.

    As for sample code that uses c# you can see some at

    http://www.comm64.com

    but that's just going to show you RS232 but it's a start I suppose.
    IANS I need your help and your guidance!

    Right now, im facing a problem which i need to use this acute face recognition device + keypad card reader datas to be transferred over to my laptop. I realised if i were to transfer all the datas from the face recognition device + keypad card reader i required to use a serial port to do so. But laptop doesnt has a serial port. What can i do? Here's the port description.

    Port 3-1 12V Power Out
    Port 3-2 12V Power Out Gnd
    Port 3-3 Wiegang In Data 0
    Port 3-4 Wiegang In Data 1
    Port 3-5 Wiegand Out Data 0
    Port 3-6 Wiegand Out Data 1
    Port 3-7 Rs-232 Tx
    Port 3-8 Rs-232 Gnd
    Port 3-9 Rs-232 Rx
    Port 3-10 Rs-485 +
    Port 3-11 Rs-485 -

    The first 4 ports have been used for the keypad card reader.
    Now i need your guidance on how to make this 2devices to connect to laptop and port the information back to the devices and computer. Is that possible? Can laptop be the central monitor to modify/changing informations? Would it be a better choice if i were to post the typical wiring schematics to show you?


    Thanks alot!

  15. #15
    New Member
    Join Date
    Oct 2015
    Posts
    2

    Re: C# with RS485/Serial Port Communication

    Our USB to RS-485 converter is driver based. We have drivers for this on all Win 7 and prior OS. Simply install the driver, connect to your USB port and wire your device. The com port number appears in your device manager. You can then open a uart connection to your RS-485 device.
    http://www.icpdas-usa.com/tm_7561.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width