HiI using the IO.Ports.SerialPort.GetPortNames to get the avaible comport names. This works fine with the cabled comport but the bluetooth comport sometimes give extra characters at the end of the comport name.
Below are some examplesCOM3 is shown as COM3 or COM3i or COM31COM9 is shown as COM9 or COM9c or COM92COM31 is shown as COM31 or COM31iI am able to coupe with removing the end character if it is not a number (e.g. COM3i converted to COM3) but how do I remove the extra characters if they are numerical (e.g. COM31 converting to COM3) please note that sometimes the comports are displayed correctly.Is there a way to of solving this and retreiving the correct comport names without the extra digits.Thank you for any help in advance. Sorry to disturb again, but why is this coding displaying??
This topic describes how to use My.Computer.Ports to receive strings from the computer's serial ports in Visual Basic. To receive strings from the serial port. Initialize the return string. Dim returnStr As String = ' Determine which serial port should provide the strings. This example assumes it is COM1.
Can you try this, load this hex to a PIC16F877a with 20Mhz crystal, set baudrate of VB.net to 9600, connect TX of PIC to RX of PC and RX of PIC to TX of PC. Just paste it in notepad and save it as whatever.hex then burn it with your programmer:3000C8326C30:302B4217EE327410E2000202AE935F430EB03178C17F3:10000C0B28A0:0D03170F08E1:0C1E2B08F0083168C170C14BD:0C0D0E0D7F39:0D03170F08A1:0C1E4B0A0030803178F008D0A03198F0A8D:10138A1230FC:10F800FD0F80B67287B30F700F70B6E28C2:1000E08A140183131F301A:1090308312D2:0083161F149F141F1C0031F5D:30A100FA30A2005F8316A8:286300B8:02400E007A1F1FF. Hi tiktakx,Thanks again for the tutorial, it’s helped me get started with no formal VB background. It seems like DataReceived event has a lot of limitations.It is best to use non-string variables type, right?
I can’t even enable the timer via timer1.enabled = true if the statement is inside the DataReceived event andIf i use select caseSelect Case MaVaCase 0Rohead = “North”Case 1Rohead = “East”Case 2Rohead = “South”Case 3Rohead = “West”Case ElseRohead = “?!”End SelectThe string value stored, Rohead is not modified although the variable is declared just underneath the Public Class. Hello tiktakxI was hoping you could help me with a project I am doing.I need to be able to read in XML data through a serial port to a dataset and then bind it to my controls.I am able to read in the continues stream of XML data, and send commands to get stored XML data. I believe my program is treating all the XML as text and thats fine but i don’t understand how to bind it to controls.
Either way i’d like to do it right and read it into a dataset and then bind it to controls within the delegate.Any assistance or tips would be most welcomed. Hi,I cut and pasted the code but I get a whole bunch of errors.
I don’t know why.Thanks for any help, will be greatly appreciated!Error1‘Private Sub frmMainLoad(sender As Object, e As System.EventArgs)’ has multiple definitions with identical signatures. Form1.vb 317Error2Statement cannot appear within a method body. End of method assumed.Form1.vb 285Error3‘myPort’ is not declared. It may be inaccessible due to its protection level.Form1.vb 309Error4‘myPort’ is not declared.
It may be inaccessible due to its protection level.Form1.vb 37 29Error5‘myPort’ is not declared. It may be inaccessible due to its protection level.Form1.vb 38 31Error6Type ‘SetTextCallback’ is not defined. Form1.vb80 26. TiktakxThanks for the great tutorial. I have 3 questions:Q1. How do I stop the txt scrolling off the bottom of rtbReceived?
I cannot find any property to stop this happening.q2. When I click btnDisconnect I wish to send 2 bytes to a motor controller to make sure the motors have stopped.
The 2 bytes to then be seen in rtbReceived via the port loop-back. I think the port is closing too quickly but using sleep just locks up the form. Code follows:Private Sub btnDisconnectClick(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnDisconnect.ClickSerialPort1.Write(SabertoothMLSTOP & SabertoothMRSTOP & vbCr)Thread.Sleep(100)SerialPort1.Close ‘Close our Serial PortbtnConnect.Enabled = TruebtnDisconnect.Enabled = FalseEnd SubQ3.
Is there a VB joystick or pad that I can use on the form and control with a mouse pointer. Like a slider but in X & Y.Many thanks for your help. I am using the following code to capture lines from the serial port (Com4):Public Sub MySerialportDataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles mySerialPort.DataReceivedDim strSTRBUFF As String = mySerialPort.ReadLineReceivedText(strSTRBUFF)Dim strtexttest As String = Trim((strSTRBUFF))Dim CALLPARSESUB As delSERIALDATAPARSE = AddressOf PARSESERIALDATACALLPARSESUB.Invoke(strTEXTTEST)End SubThe sub CALLPARSESUB calls other methods in another form (call that form FORM2). Those methods then need to write text to the serial port.When the code in FORM2 is executed, the serial port has been closed.
I downloaded your SerialPortInterface.I imported it into Microsoft Studio Version 10.It loads fine.I connected my PC to another PC using a null modem cable. Using hyperterminal I can go to either keyboard, type and see the characters on the other PC.Using your program on my PC and hyperterminal on the other, I can use your SEND button and send text to the other PC and hyperterminal will display the characters. I cannot send from hyperterminal and see them in your program. I type on the remote PC, I see a delay in the characters being echoed back to the screen on the remote computer, but they never appear in your program.In debug mode, the SerialPort1DataReceived routine does not appear to get called. It is like the event handler does not get raised.Can you get me on the right track?The code I am developing will need to keep reading in small chunks of data from the comm. Port and send some back eventually.Thank you,Rob Sobol. Hi tiktakx,First thanks for your kind share the code to public.
This help me a lot. It work fine in my desktop applicationCurrently i had a project that need to used serial port profile in compact framework (window mobile application).after i convert everything to window mobile form.
The bellow code show me an error:cmbPort.Items.Add(myPort(i))//the target version of the.NET Compact Framework does not support latebinding.i had search and try to solve the error, but until now i still not get the solution.Kinly advice how can i solve for this? And any website or reference can provide? Hi, thanks because sharing help my project a lot.
I had testing this source code personally and it works. Thanks a lot.currently i need to change the platform to window CE (to window mobile device). I apply the same code to the new platform, it show me the error bellow:cmbPort.Items.Add(myPort(i))//The targeted version of the.NET Compact Framework does not support latebinding.i search a lot from net, but i can’t meet the solution.Kindly advice, how can i solve for this or any website or link provide me to learn from there?Thanks in advance. Great job!I adapted your code to my project, when I type R, I actuates a motor which turns right and when I type L, I actuates the motor to the left on my picaxe 28×1 and it works “nickel”.When I type V (read a value from one of the A / D converters on my 28×1) I see appear in the rich text message box on my 28×1: “DAC 1 VALUE:xxx” (value 0 to 255 max)it works fine but I would recover “only the value” and display it in a big label.I do not see how to do it from your code.if you could help methank you in advance.(sorry for the translation but I’m French). This is a really useful example. Thank you so much. I’m using your program to read weight from a scale in my lab.
I would like to create a feedback control loop with the readings. The scale transmits data continuously in a format “ASNG/W+169.50 kg” but the ‘169’ portion could become ‘ 69’ or ‘ 9’ or ‘ ‘. I’m trying to parse out the weight as a VB newbie, using messageBox.Show to test the parsing.The challenge is that as soon as I start using the messageBox, the text coming in gets long, like several readings concatenated with vbCrLf in between. So, I write my regex for what I see but then when I remove the messageBox the string is much shorter and rarely includes the entire weight so comes up Null most of the time.I think I need to maintain an array or a string and pop each value onto the end as I read it, and then parse out the weight each time from a 20 character string or so. Does this sound logical?
Is it a common problem that you would have a code snippet for?Cheers!!! :This is the first time someone took the time in showing the baby steps for rs232 use in vb 2010.
I used it to display n string that is send from a weighing scale.With the same code how can i only display a certain part of string? The scale sends the string constantly. Looks like this(ww00000000kg), it then repeats it self.How can i only update the the string in stead of adding it constantly?Many thanks (ZS1QC)hi i face the same problem.
When i click send to other pc, it can show in the word richtextbox too(but when i check with BlueSoleid, it show me i already revived from other device, but it can’t show me in richtextbox.Kindly advice. Where can be the problem?
:first of all I am appreciated you for this article.but I have a problem.I have done everything you have said as seen image.Program could open the virtual serial port but when I click btnSend, the data does not appear in richtextbox.Where can be the problem?hi i face the same problem. When i click send to other pc, it can show in the word richtextbox too(but when i check with BlueSoleid, it show me i already revived from other device, but it can’t show me in richtextbox.Kindly advice. Where can be the problem? Thank you tiktakx for a good example. This gave me a good leg up on switching from VB6 to VB2010. Serial comms is crucial to everything I do.I few comments and extensions to the example, which may help others who follow.
Copy/pasting your original sample code into VB2010 seemed lose the “Handles” bit of several event handlers. No idea why, but I had to enter them back in manually. I replaced your “IO.Ports.SerialPort.GetPortNames ‘Get all com ports available” which populates the port selection combox with unfriendly COMnn numbers, with code that provides friendly names like “USB to serial adaptor (COM255)”. I got the code by digging around on some other sites. Another thing: Pure binary dataI spent today discovering how to reliably get binary data in and out of the serial port. In other words, getting all 256 binary codes that can be represented in a byte to be passed through SerialPort without corruption. I started with the above example.
What I discovered is that under certain conditions codes &H80 and above may be corrupted, more often or not changed to &H3F. I was using one of my company’s controllers ( ) the other end, with a program that would sometimes send me stuff, sometimes receive and action stuff and sometimes simple echo characters (all depending on some input switches).My conclusion (a result of much googling!) is that you need to execute the following two lines when opening SerialPort:SerialPort1.Encoding = System.Text.Encoding.GetEncoding(1252)Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.InvariantCultureThe first line is totally essential. The second sometimes makes a difference, sometimes not.
I tested this as hard as I could with the localisation set to a number of different countries (Control PanelRegion and LanguageFormats in Win7). With both lines present I could not make it fail. My final program sends out every possible code and checks every return, reporting any errors.I tested on just one computer under Win7. I will be testing on other machines and other operating systems, real and virtual.BTW, I have been programming serial ports since the 1970’s, on DOS and before.
Micro$oft have NEVER got it 100% right.NET’s SerialPort seems to follow this established tradition! I have never been able to get this code to run. As soon as I connect the loopback jumper and receive a character, it crashes with the following message:“FatalExecutionEngineError was detected”“The runtime has encountered a fatal error. The address of the error was at 0x6db83a56, on thread 0x1818. The error code is 0xc0000005.
This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.”I take it this is one of the threading errors the “delegate” statement was supposed to prevent?
I tried it on three different computers, one XP and two W7, each with a fresh installation of VB 2010 Express. I can run equivalent code in VB6 with no problems at all. I am learning Visual Basic 2010, using Visual Studio 2010. I have a frmMain that has buttons to call various other forms – frmSetup, frmLapClock, frmStopWatch, etcI would like to initialize and declare my Serial Port once (load settings from txt file), then be able to use it in all of the forms. This includes frmSetup where I can test and change to port settings if needed. While I can do this during the formLoad process of the frmMain, I cannot reopen the port in sub forms.
I tried making the Serial Port public and a variety of other methods. I typically drag the serial port icon from the toolbox into the frmMain. Also tried manually setting it up by typing in the commands + setting up a separate module.I am familiar with setting this up on one form and had success with that – many example available on the web.Any help would be greatly appreciated.RW. Thank you, works great. The problem I am having is that instead of using the Transmit Data box I am sending a hard coded string which works fine until I try to send a second one immediately after the first, then instead of reading and then sending the second string, it tries to send all three at the same time. All of these work individually or from the Transmit Data box.
Example:SerialPort1.Write(“CONNECT ON” & vbCr) ‘This always has to be sent first, I get a promptbackSerialPort1.Write(“LISTLOG” & vbCr) ‘This returns a list of log file of incidents & resultsSerialPort1.Write(“REVISION” & vbCr) ‘This sends back data about the software revisionCan you please provide a solution? Cutting and pasting the entire code (and only )into visual studio 2010 VB on a win 7 64 bit laptop I get a notice about the cmbPort (little red marker) everywhere in the code where cmbPort is.It says: ‘cmbPort’ is not declared.
It may be inaccessible due to its protection level.There are four corrections to choose from. If I pick the first “Generate method stub for cmbPort in SerialPortInterface.frmMain.The red markers go away but end up with this code which doesn’t match yours???Private Function cmbPort As ObjectThrow New NotImplementedExceptionEnd FunctionWhatz up here? Hi Really excellent like everyone says! One small bug I found when receiving streamed data. I have 30 chars per line of data coming in at 50hz constantly. I use “ReceivedText(SerialPort1.ReadLine) instead of readexisting so I get clean lines.
I also changed the text box so it overwrites each line – other wise it just fills up too much.Bug is – If I click disconnect while data is being received I often get this error. “The I/O operation has been aborted because of either a thread exit or an application request.” at ReceivedText(SerialPort1.ReadLine.Is there a preferred way to trap this? I have used try /catch with a msg warning if the error occurs – this seems to handle it – but sometimes i just get a crash with no information – just a freeze – though maybe it’s unrelated?Thanks fro your help. Hi,First of all, I would to thank you for your help allowing us to use your sample code. I am currently using your example to enter Part number to a device, my device has the following internal commands for entering P/N and S/N. c8 xxxxxx and caxxxxxxx. Where c8 & ca are device internal commands and x are P/N & S/N.
Sometimes users forget to add the c8 or ca when they’re entering it in the “Transmit Data” box. Thank you so much for this tut, it’s been quite helpful.I used the code and every part of it worked as it should, but I needed to tire the received data to specific variables, like in a system test situation where you set the values of different input variables and read the output status. So I decided to have labels named after these output status and instead of RichTextBox inside the GroupTextBox I replaced it with different TextBox named after these specific output status.It’s been quite challenging and frustrating to get these values in their rightful positions / locations.I’m very new in this environment visual basic, few day old experience. I will so much appreciate any help I can get to enable me resolve this.Thank you once more.
serial.tools.list_ports¶
This module can be executed to get a list of ports (
python-mserial.tools.list_ports ). It also contains the following functions.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |