serial port - com

I toke from the VB6 the example about using the serial port with MSComm.
I run this program in VB2005 after it was upgrade ofcourse by the VB2005
and try to send and receive strings in a loop(1-1000).
But sometimes in this loop the string that I'm sending is stuck or something that I don't understand why

I run this loop with the some strings a lot of times and everytime is a different
string that stuck. if someone can tell me why

In VB2005 there is something similar to MSComm that I can use



Answer this question

serial port - com

  • Large

    Hi,

    Thanks for the files it was very helpful.

    I have a little problem that I can't figure out how can I solve it.

    I want that my program will work in a loop and check if something come from the serialport or if there a file that another program sent to me.
    something like this:

    Dim a
    Dim i as integer, flag_file as short
    i=0
    flag_file=0

    Do
      If Not (a = Dir("c:\temp.txt")) Then flag_file = 1 
       i = sp.readbyte
    loop untill (i>0 or flag_ file=1)


    but the problam is that if nothing comming from the serialport it's stuck and wait.
    I'm using readbyte and not readline cause I can get chr(0) or enter (asci 0 till asci 255) from the serailport.

    there is solution for that

    thanks again,
    yaniv




  • rengarajan75

    Hi,

    I have e-mailed the sample in VB2005 to you.

    Regards,
    Vikram

  • ashis.lun

    Hi,
    I didn't notice that you use with " try " and "catch" so now it is working as I wanted.

    But now  I have another problem I tried to sent chr(129) and I received in the other computer chr(63).

    when I sent chr(0) till chr(127) it work fine.

    from chr(128) till chr(255) some of them are fine and some of them
    I'm getting chr(63)

    So how can I fix that

    yaniv




  • Sean Cassell

    I tried chrw(x) it's still work the same,

    this is how I open the port: (maybe I didn't do something right )

    sp.PortName = "COM1"

    sp.ReadTimeout = 500

    sp.DtrEnable = True

    sp.RtsEnable = True

    sp.BaudRate = 19200

    sp.DataBits = 8

    sp.StopBits = StopBits.One

    sp.Parity = Parity.None

    sp.Open()

    if you have another idea I'll be happy to try....


  • Sam Heald

    Hi, thanks again

    But I can't figure out how can I use it in VB2005.
    I tried to drag "SERIALPORT CONTROL" from the "toolbox" to the "form1.vb(design)"
    but after that I didn't know how to apply to this serialport.

    If you can convert it to VB2005 it be great

    thanking you in advance
    yaniv




     


  • MHenke

    Thanks for the quick answer,

    But I'm Beginner in VB2005 programming and I be glad if I can get example
    of how to add this SerialPort control and how to use like the basic command
    as open the SerialPort,write,read and close.

    Regards,
    yaniv


  • Anilesh Lakhtakia

    I'm really appreciate it...

    my email : yaniv@turbototo.com

    thanks again,

    yaniv


  • cdemez

    Hi,

    You do not even drag drop the control. You can create an instance by declaring a variable of type SerialPort and use that. Anyways, I have that sample converted.

    Let me know your email Id so that I can email the project to you.

    Regards,
    Vikram

  • CharlemagneJunior

    Hi,

    Here's a simpler example - but still in C#.

    Let me know if you can figure out, or I will convert it to VB2005 and send it to you:
    http://www.codeproject.com/csharp/SerialCommunication.asp

    Regards,
    Vikram

  • mikeparris

    Hi,

    Visual Basic 2005 has a separate SerialPort control which you can use for serial communication.
    http://msdn2.microsoft.com/en-us/library/system.io.ports.serialport.aspx

    Sample available only in C# - http://www.gotdotnet.com/team/clr/bcl/demos/demos/zipfiles/SerialLCDCS.zip

    Regards,
    Vikram

  • xensu

    try using chrw(x) instead of chr(x)

    Dustin


  • Olivier Mascia


    It looks like his code is looking for eight bit enties and not 16 so I'm really sure that Chrw will not work. My understanding is that these days the chrw chr are both 16 bit entities.

    It looks as if the byte high-bit is being used as a sign bit in places.

  • MSKarsin

    Hi

    I have graduation project that is about RS-232 serial cominication. I am developing my code with .NET 2005.

    I want to control RS-232,

    code;

    private void write_click(object sender, EventArgs e)
    {
    if (!serialPort1.IsOpen)
    {
    serialPort1.Open();
    }
    string sendmesaj = textBox1.Text+"-->>>>";
    serialPort1.WriteLine(sendmesaj);
    }

    private void read_click(object sender, EventArgs e)
    {

    string i=serialPort1.ReadLine();
    textBox2.Text ="<<<<---"+i;
    serialPort1.Close();

    }

    when I send data that is ony between 1 and 5 characters, it is ok. However when send characters more than 6 for exmaple "abcdefghi" it is faild.

    please help me

    thanks a lot



  • PaulCDev

    Hi,

    Look I'm still a rookie in VB2005 but I'll try to help you...

    So I guess that you are trying to connect between two computers.
    and you have problem with sending characters but, I'm thinking that the problem
    is receiving the characters on the other computer.

    You need to know how many characters (or till when ) to receive from the serial port otherwise after you sent the characters that you want,
    the receiveing computer will still wait for more data till time out will appear.

    When I wrote a similar program in VB2005 I had a problem that I sent char(13) (as you know that equal to end of line) and I receive on the other computer chr(129).

    that mean that the receiving computer didn't know that was the end of the line and wait for more data.

    So I worked differently I read the first byte that tell me how many bytes I need to receive. and then I know when to stop receiving characters.

    But then again I'm not sure that is the same problem in your program...

    Hope that I help you some how.....

    Regards,

    Yaniv


  • serial port - com