Author Topic: Making a Serial RS232 <-> Ethernet Converter  (Read 18721 times)

enliteneer

  • Newbie
  • *
  • Posts: 1
    • View Profile
Making a Serial RS232 <-> Ethernet Converter
« on: September 13, 2005, 02:05:43 PM »
Reading the description of the SBC65EC, it says typical applications include 'Protocol Bridge applications - Ethernet to USART'.   This seems perfect, because most of the other converters Ive seen are bulky boxes that ASSUME you have a PC running a virtual COM driver.

I have no such PC, I have a small 8051 micro with RS232, that I would like to have RECEIVE data from an ethernet network.   The problem then, is the software protocol conversion.   Would the 8051 have to packetize and depacketize ethernet data into a raw protocol before and after communicating with the SBC65EC?  Or, should the 8051 be left untouched and all the serial to ethernet / ethernet to serial conversion takes place in the SBC? 

I really would like to use the SBC65EC, so if anyone has any ideas how I would go about this, Im all ears!


Administrator

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
    • http://www.modtronix.com
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #1 on: October 06, 2005, 09:14:31 PM »
Hello

All the conversion RS232<-->Ethernet conversion can be done by the SBC65EC. I have mailed you an sample program that does UDP<-->RS232 Serial conversion for the SBC45EC. To use with the SBC65EC just copy relevant parts of code from main.c and past into mxwebsrvr.c in SBC65EC source code.

*** Modtronix Engineering Support ***

Will

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #2 on: October 09, 2005, 01:10:46 PM »
I am also interested in doing this, please could you send me the sample program as well.

Thanks Will

eddyinsane

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #3 on: October 13, 2005, 09:34:34 AM »
Hi, I would also be interested in this infomation. Isnt there a website or something with this all on? I have done some google searching and found nothing. Still if you could send me the info would be a great help.

Thanks

Ed

eddyinsane

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #4 on: October 14, 2005, 10:46:15 AM »
Ok, I have got my compiler working (Has recompiled the web server). However when I attempt to compile the valweb.mcw, valweb_debug.mcw or valweb_ftp.mcw. It fails to compile with 1 error:
"Error - Coff file format for 'E:\[path]\c18cfg.o' is out of date"
([path] is the location of the file on my pc)

However it creates this file while compiling I assume from c18cfg.asm. Its got me! Do any one understand this error or know a way of fixing it? I am using the student version of MPLAB IDE with C18 all installed and working.

Thanks

Ed

« Last Edit: October 16, 2005, 04:22:34 AM by eddyinsane »

tlk

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #5 on: October 14, 2005, 11:56:41 PM »
Hello

All the conversion RS232<-->Ethernet conversion can be done by the SBC65EC. I have mailed you an sample program that does UDP<-->RS232 Serial conversion for the SBC45EC. To use with the SBC65EC just copy relevant parts of code from main.c and past into mxwebsrvr.c in SBC65EC source code.



Hi !
May be can You send the same sample program to me, my mail addr is public.(sorry for my english I`m from Hungary)
Thanks.

tlk

katurcot

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #6 on: October 16, 2005, 10:21:19 AM »
I have a similar application:  I want to post to a web page through the SBC65 data from another processor connected to the SBC65 with a serial interface.  It sounds like your UDP<-->RS232 Serial conversion code is a solution.  Assuming it is I would also like a copy.  Thanks for your help.
« Last Edit: October 30, 2005, 07:58:56 AM by katurcot »

yaonabine

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #7 on: October 17, 2005, 02:16:44 AM »
Hello

All the conversion RS232<-->Ethernet conversion can be done by the SBC65EC. I have mailed you an sample program that does UDP<-->RS232 Serial conversion for the SBC45EC. To use with the SBC65EC just copy relevant parts of code from main.c and past into mxwebsrvr.c in SBC65EC source code.


Hi all ,

I am also interested in these source codes , could you send me a copy please? my address is [email protected] .
I also have some other questions I would like to ask . I am new to microcontrollers , and want to know how , practically ,  I can use the SBC65EC board to monitor data sent through the RS232 port, or through the I/O pins .Any WWW cite you can send me to , any document (e-book)... I need your help .
A last question on the SBC65EC : are the serial port and the USART pins ( SIG0 and SIG1) independant so that they can be used for different data procedding .
Please send me any help as soon as possible .

Administrator

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
    • http://www.modtronix.com
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #8 on: October 17, 2005, 10:19:26 PM »
Hi katurcot

Can you please send me your mail address so I can also send you a copy of the code.

The SBC65EC can be used to monitor data on RS232 and on the I/O pins. Best is to download the "Modtronix SBC65EC Web Server" from www.modtronix.com/products/sbc65ec and modify it. The monitoring of the I/O pins is all done in httpexec.c, and is well commented in the code.

The SBC65EC has two independant USARTS. The one is connected to the RS232 driver on the board, and the second is connected to port G pins.
*** Modtronix Engineering Support ***

imxo

  • Full Member
  • ***
  • Posts: 13
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #9 on: October 18, 2005, 01:06:19 AM »
Appreciated if you could also send me a copy of this sample code, to the im1030 at mails.fju.edu.tw
imxo - I'm eXtra Old, well... sort of  ^O^

imxo

  • Full Member
  • ***
  • Posts: 13
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #10 on: October 19, 2005, 12:46:32 AM »
Hi katurcot

Can you please send me your mail address so I can also send you a copy of the code.

The SBC65EC can be used to monitor data on RS232 and on the I/O pins. .......

I was wondering that whether or not this code is the one posted in http://forum.modtronix.com/index.php?topic=69.0 under the title UDP Sample Code
imxo - I'm eXtra Old, well... sort of  ^O^

davo22

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #11 on: October 19, 2005, 02:02:50 AM »
Hi, May I get a copy also. [email protected]. Regards Davo

dgood

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #12 on: October 22, 2005, 10:39:56 PM »
I'm trying to use this the SBC45EC as a serial <-> ethernet converter but I'd like to use TCP instead of UDP.  Is there some sample code for that?  I will write it myself if nessessary, but I was hoping since there were so many requests for this application, that someone already had the code written.  If it is, it would be worth putting up on the site somewhere to save the trouble of emailing it individually to everyone.

Thanks for the help!
David Good

imxo

  • Full Member
  • ***
  • Posts: 13
    • View Profile
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #13 on: October 23, 2005, 09:17:41 AM »
I'm trying to use this the SBC45EC as a serial <-> ethernet converter but I'd like to use TCP instead of UDP.  Is there some sample code for that?  I will write it myself if nessessary, but I was hoping since there were so many requests for this application, that someone already had the code written.  If it is, it would be worth putting up on the site somewhere to save the trouble of emailing it individually to everyone.

I second the motion, regarding sharing the code by posting it directly on the site, in so doing David won't have to e-Mail them to each individual one by one, especially he has been so busy to not being able to respond at all.

I did see UDP code being posted in one thread, while ironically at the same time lots of replies were requesting it without getting reply in whatsoever.

From this post http://forum.modtronix.com/index.php?topic=12.0, I'm sure David had the code way back to September last year.  My recent posts didn't receive any reply at all.    :-(

Perhaps it's a good idea to have someone, who had received the code, post what he ever received as the other way around.   :-)
imxo - I'm eXtra Old, well... sort of  ^O^

Administrator

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
    • http://www.modtronix.com
Re: Making a Serial RS232 <-> Ethernet Converter
« Reply #14 on: October 24, 2005, 01:33:00 AM »
G'day all

OK, I have placed it on the server. It can be downloaded from www.modtronix.com/soft/valweb.zip. The code does UDP<-->RS232 conversion. It uses an interrupt driven USART ISR, with a circular buffer.

See the main.c file for details. The project uses the SBC45EC and an older version of the Modtronix TCP/IP stack. Best is if you just copy the couple of relevant functions from main.c and paste them into your project (download new source code from www.modtronix.com). Just as
long as it uses the Modtronix TCP/IP stack, it should work.

Please no bitching if the code does not do exactly what you want. This is a working project, and is used on coin machines that are working in field. It is stable. Converting it to be used with the new version of the stack, or for use with the SBC44EC, SBC65EC or SBC68EC should be very simple to do - if you however have to change some defines or whatever, don't complain too much ..... dear sir "imxo"  :-)

In the Udp2SerProcess() function the received RS232 data is checked for protocol specific information relevant to this project - this can be removed. The following code checks this protocol specific information (only complete message packets received via RS232 are placed in packets and sent via UDP) relevant to this project:
Code: [Select]
    /////////////////////////////////////////////////
    //Was anything received on the USART - store it and schedule for transmission
    //once all bytes are received
    while( !serRxBufEmpty()) {
        //If the contents of the "Ser to UDP" buffer is waiting to be TXed via UDP, break
        if (flagsUDP2Ser & UDP2SER_TX_TXBUF) {
            break;
        }

        c = serGetByte();

        //This is the first byte of the Validator command, which can be SOH, ACK or NAK
        if (bytesRxedSer2UDP == 0) {
            //ACK and NAK
            if ((c == 0x06) || (c == 0x15)) {
                //Can be sent straight away
                flagsUDP2Ser |= UDP2SER_TX_TXBUF; //Indicate the "Ser to UDP" buffer must be TXed via UDP
            }
            //SOH byte was NOT received, continue
            else if (c != 0x01) {
                continue;
            }
        }
        //This is the command lenght byte (second byte of packet)
        else if (bytesRxedSer2UDP == 1) {
            currValCmdLen = c;
        }

        //Add the received byte to the Validator Command buffer
        bufSer2UDP[bytesRxedSer2UDP++] = c;

        //If
        // - Last byte of validator command has been received
        // - The buffer full
        //set flag for UDP to send it!
        if (bytesRxedSer2UDP > 2) {
            if ( (bytesRxedSer2UDP >= currValCmdLen)
                    || (bytesRxedSer2UDP >= (BUF_SER2UDP_MAXSIZE - 1)) )
            {
                flagsUDP2Ser |= UDP2SER_TX_TXBUF; //Indicate the "Ser to UDP" buffer must be TXed via UDP
            }
        }
    }

To simply transmit everything that is received via RS232 in UDP packets, replace the above code with:
Code: [Select]
    /////////////////////////////////////////////////
    //Was anything received on the USART - store it and schedule for transmission
    //once all bytes are received
    while( !serRxBufEmpty()) {
        //If the contents of the "Ser to UDP" buffer is waiting to be TXed via UDP, break
        if (flagsUDP2Ser & UDP2SER_TX_TXBUF) {
            break;
        }

        c = serGetByte();

        //Add the received byte to the Validator Command buffer
        bufSer2UDP[bytesRxedSer2UDP++] = c;

        //If
        // - User check is true
        // - The buffer full
        //set flag for UDP to send it!
        if ((use check) || (bytesRxedSer2UDP >= (BUF_SER2UDP_MAXSIZE - 1)) ) {
            flagsUDP2Ser |= UDP2SER_TX_TXBUF; //Indicate the "Ser to UDP" buffer must be TXed via UDP
        }
    }
In the above example, the user check has to be true before the received RS232 data is sent. For example, to only send the received RS232 data once there is 5 or more bytes to send, replace the (use check) if condition code with (bytesRxedSer2UDP >= 5).


« Last Edit: October 24, 2005, 01:36:48 AM by Administrator »
*** Modtronix Engineering Support ***