Vb.net serial port dtr
I can use the direction control of the module to change the comms direction of the interface and just use a normal terminal program to do my testing, but this is a little messy as I have to open up the interface module and wire it up. I thought I could just make up a small program with some buttons to send the various commands this bit works and then have a box where I could diasplay the responses and the whole testing bit could be a bit more elegant.
I could put together an intelligent interface that could buffer the responses and somehow then relay them to the pc as a small processor inside the unit could wait untill it sees RTS before sending. I believe this is the approach taken by some colleagues that have given up on what I'm trying to do. I may have a quick shot at doing it in Delphi see how it goes. I've worked in a Telphony appliction written on Borland Delphi 6 and i have found data losses, specially the first leading bytes in our protocol, but the next bytes usually arrives without problems.
So, I made a work around is to start the transfer with 10 characters 0x00 while the microcontroller enters Serial ISR and it will not buffer the stream untill a non zero has been received then it start to buffer data, once the terminator is validated and seems to be correct, it waits for the sync byte or leading zeroes again.
After the project is complete I decided not to use the RS again because of its complications and the owner of the company should buy another type of cables with 4 wires and use the RS instead if he need to go for large distances. The trick of RTS then send leading zeros to init transfer then send data afterwards has solved the problem in our project. Sleep 2 ; serialPort1. Ask a question. Quick access. Search related threads. Remove From My Forums. Answered by:.
Archived Forums. Visual Basic. Not for VB6 questions. Sign in to vote. Hi I'm back on VB after a long while. Click SerialPort1. Wednesday, October 18, AM. Write Chr command 'Send message SerialPort1. Wednesday, October 18, PM. Make sure that you use Hardware Flow control!! I think you can test this by measuring the voltage level on the RTS pin.
Hope this can help! Interfacing Hardware is really an exciting work, Have some fun!!! EventArgs Handles Button1. Click SerialPort1. Sleep SerialPort1. Improve this answer. Thanks for the feedback. It must be something else that is keeping my sensor from responding then.
I have to say the description attached to the DTREnabled property is not that clear. It says something to the effect of "Enables DTR during handshaking". Check the pinout of the cable. It might be contributing to the problem. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science.
Stack Gives Back It may be helpful to download it! I have spend maybe a month writing the tutorial and digging up all the background knowledge. If beginners would just spend a fraction of that time trying to understand it, it could bring them very far.
Unfortunally, many beginners don't bother to do that. They just write some code without the slightest understanding of what they are doing and if they get an error message they try another way instead of trying to understand what is wrong and correct it. Everything you need is in that tutorial. The sample program is even able to do very much what you want.
The only thing you have to do is to connect the switch and maybe a protection resistor as described above and see that the CTS or DSR "lamps" which are actually buttons shows the state. Then you can modify the program to your needs. I know that the tutorial has grown to a size where it gives many most beginners headache, but most of the tutorial is basic knowledge about. Net, which you will need anyway.
Just take it easy step by step. When I started to do electronics approximately 45 years ago, my first project was a crystal receiver, that is, a small radio with only three components. Beginners nowadays want to start with a 3D program or a data base. The content you requested has been removed.
Ask a question. Quick access. Search related threads. Remove From My Forums. Answered by:. Archived Forums V. Visual Basic Express Edition. Sign in to vote. Hi i need help programming a serial port in visual basic I have opened the serial port by using serialport1. I want to have a contact switch attatched to 2 wires, one going into pin 4 on the serial port and the other in pin 6. And when the switch is activated then i want it to activate a button on my program. How would i go about doing this, any help is welcome.
Thanks Kind regards Willie. Friday, February 20, AM. PerformClick method to activate your button. I am not sure if you are allowed to call the PerformClick method directly from the eventhandler for the PinChanged event possible cross-thread call , but if not, you can just use the MethodInvoker delegate and a BeginInvoke or Invoke call to send the message to the UI thread. This is all described in the tutorial. Everything should be made as simple as possible, but not simpler.
Friday, February 20, PM. The switch must be connected between the output and the input. Thanks for all the help, Carsten great link btw, shows alot and helps alot. Do these 2 pins just send data or is there a voltage across them so if i connect the 2 together my comp wont blow up lol.
Im only a beginner at this so this is the first time ive really looked into serial port useage. Edit don't work again! Keeping in mind i am using visual basic express Object, ByVal e As System. EventArgs Handles MyBase. Load SerialPort1. Open If SerialPort1. DsrHolding Then Label EventArgs Handles button1. Click Me. Close ' Closes the program serialport1. I did borrow most of your code and try to adapt it to vb express ;. Thanks for the input kind regard willie. Close End Sub Then it is done automatically when you close the application.
Ok so i tried that didnt work, was thowing up errors so i tried this and it doesnt seem to trow up errors but in scared to test it on this machine as this is my work machine, i will try my old laptop when i get home tonight, any way heres what i have put in. Close SerialPort1. Close End Sub All the rest of my program works so no point in sending that.
But anyway again thanks for the help, as i said, i will try this when i get home tonight at 5. Thanks again all, i will post in sometime tommorrow or monday to let use know how i got on Kind regards Willie. Which errors? The input impedance of an RS receiver is approximately 5 kohm and the triggering level is approximately 1. This means that you only need approximately 0.
Therefore, you don't need to short circuit the pins directly by means of the switch. You can for example add a kohm resistor in series with your switch. This will limit the worst case current to less than 2. In this way, you will not be able to burn anything off no matter what you do - except if you short circuit the pins in the plug. You still miss "" around text! It is Label I need to push the button to close the application any way but i might just put in your code aswell because if the program shutdown due to a iwndows error then obviously the button wont be pressed.
I will have a go and see what i can do. Thanks again Mate. The reason i dont put "" around the text is because the rest of my program hasnt got "" around the label text. The errors are with the "withevents". It says "Error 1 'WithEvents' is not valid on a local variable declaration.
Load Dim serialport1 As New System. SerialPort SerialPort1. IsOpen Then SerialPort1. But all i have done is declared serialport1 as a new serial port. Is that not the same as dragging a serial port onto form 1? The SerialPort declaration shall not be local, but global.
0コメント