Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 6:21
professionalMichael Fritzius30-Jul-07 6:21 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 7:47
sitebuilderLuc Pattyn30-Jul-07 7:47 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 6:53
professionalMichael Fritzius30-Jul-07 6:53 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 7:03
sitebuilderLuc Pattyn30-Jul-07 7:03 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 7:09
professionalMichael Fritzius30-Jul-07 7:09 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 7:34
sitebuilderLuc Pattyn30-Jul-07 7:34 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 7:38
sitebuilderLuc Pattyn30-Jul-07 7:38 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 7:49
professionalMichael Fritzius30-Jul-07 7:49 
Here's what I have for initializing the ports:

            serialPort1.ReadTimeout = 1000;<br />
            serialPort1.BaudRate = 115200;<br />
            serialPort1.StopBits = StopBits.One;<br />
            serialPort1.Parity = Parity.None;<br />
            serialPort1.DataBits = 8;<br />
            serialPort1.RtsEnable = true;<br />
            serialPort1.PortName = "COM1";<br />
            serialPort1.Encoding = Encoding.ASCII;<br />
            //serialPort1.Open();<br />
<br />
            serialPort2.ReadTimeout = 1000;<br />
            serialPort2.BaudRate = 115200;<br />
            serialPort2.StopBits = StopBits.One;<br />
            serialPort2.Parity = Parity.None;<br />
            serialPort2.DataBits = 8;<br />
            serialPort2.RtsEnable = true;<br />
            serialPort2.PortName = "COM5";<br />
            serialPort2.Encoding = Encoding.ASCII;<br />
            //serialPort2.Open();


I added a couple of buttons that can turn on/off the ports on the fly, so I can test with HyperTerminal if needed. But both port have RTS line enabled. The ports aren't opened immediately after the program starts, but the settings are set. Just press a button and go for it. port 1 is the RS232 and port 5 is the USB.

Here's how I handle sending/receiving messages:

        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)<br />
        {<br />
            txtfromusb.Text += (serialPort1.ReadExisting());<br />
        }<br />
<br />
        private void serialPort2_DataReceived(object sender, SerialDataReceivedEventArgs e)<br />
        {<br />
            txtfromrs232.Text += (serialPort2.ReadExisting());<br />
        }<br />
        <br />
        private void sendfromrs232btn_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                //write line to USB port<br />
                sendtextfromrs232.Text += "\r";<br />
                serialPort1.WriteLine(sendtextfromrs232.Text);<br />
                //clear the text box<br />
                sendtextfromrs232.Text = "";<br />
                baudRatelLabel.Text = "Ready";<br />
            }<br />
            catch (System.Exception ex)<br />
            {<br />
                baudRatelLabel.Text = ex.Message;<br />
            }<br />
        }<br />
        <br />
        private void sendtextfromrs232_Click(object sender, EventArgs e)<br />
        {<br />
            sendtextfromrs232.Clear();<br />
        }<br />
<br />
        private void sendtxtfromusb_Click(object sender, EventArgs e)<br />
        {<br />
            sendtxtfromusb.Clear();<br />
        }<br />
<br />
        private void sendfromusbbtn_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                //write line to serial port<br />
                sendtxtfromusb.Text += "\r";<br />
                serialPort2.WriteLine(sendtxtfromusb.Text);<br />
                //clear the text box<br />
                sendtxtfromusb.Text = "";<br />
                baudRatelLabel.Text = "Ready";<br />
            }<br />
            catch (System.Exception ex)<br />
            {<br />
                baudRatelLabel.Text = ex.Message;<br />
            }<br />
<br />
        }<br />


Oh I am so stuck Poke tongue | ;-P Can I send you the entire project? I know you said you were working on something similar, so if you have the hardware ready, maybe you can get further than I have.

Take care,
Michael Fritzius
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 7:56
sitebuilderLuc Pattyn30-Jul-07 7:56 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 8:28
professionalMichael Fritzius30-Jul-07 8:28 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 8:37
sitebuilderLuc Pattyn30-Jul-07 8:37 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 8:39
professionalMichael Fritzius30-Jul-07 8:39 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 9:03
sitebuilderLuc Pattyn30-Jul-07 9:03 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 9:18
professionalMichael Fritzius30-Jul-07 9:18 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 8:02
sitebuilderLuc Pattyn30-Jul-07 8:02 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 8:37
professionalMichael Fritzius30-Jul-07 8:37 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 8:40
sitebuilderLuc Pattyn30-Jul-07 8:40 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 9:06
professionalMichael Fritzius30-Jul-07 9:06 
GeneralRe: Serial To USB Communication Pin
Luc Pattyn30-Jul-07 9:17
sitebuilderLuc Pattyn30-Jul-07 9:17 
GeneralRe: Serial To USB Communication Pin
Michael Fritzius30-Jul-07 9:22
professionalMichael Fritzius30-Jul-07 9:22 
QuestionRuntime error with MS Word Pin
André Stroebel26-Jul-07 3:41
André Stroebel26-Jul-07 3:41 
AnswerRe: Runtime error with MS Word Pin
kubben26-Jul-07 4:22
kubben26-Jul-07 4:22 
GeneralRe: Runtime error with MS Word [modified] Pin
André Stroebel26-Jul-07 4:33
André Stroebel26-Jul-07 4:33 
GeneralRe: Runtime error with MS Word Pin
kubben26-Jul-07 5:24
kubben26-Jul-07 5:24 
QuestionHigh resolution timer? Pin
Kel_26-Jul-07 3:31
Kel_26-Jul-07 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.