Introduction
Example Rs232 in VB.Net Hello. I need to ask the Form members some help, I normally use labview to interface my applications to a Notebook for monitoring some aspects of the application. I have started to learn - use VB.Net and I can now start to programm the application in VB however after hours of reading the.NET frame work 2.0. Then pair your computer with the robot via bluetooth. There open a emulated serial port. (google for you BT device) 2. Find an easy C# serial communication.
Biggest news first: The CmdMessenger development was joined by Valeriy Kucherenko. He has really improved development speed of the library and many of the changes and additions in this version CmdMessenger came from him.
Downloading and installation
The package can still be downloaded as a zipped package, but I’ve also made it available through the Arduino and PlatformIO package management system, which will make it easier to get up and running. Although, honestly, my feeling is that neither solution is ideal yet:
PlatformIO
Pro
- Supports dependency management
- Rich package format (such as inclusion & exclusion of files).Con
Con
- Not for Arduino beginners: There is no GUI, installation involves getting a Python installation , setting up the environment, etc.
- Package versions are not taken into account in dependency management, which is really important to make sure that packages don’t break
Arduino Library Management
Pro
- Integrated in Arduino UI, very easy for the end user
- Rich package format (such as inclusion & exclusion of files).Con
Con
- No dependency management. At all. I think this is a really bad idea. Without dependency management it is impossible to build upon existing libraries.
- Package submission is a fully manual process, and there is no way to check if the library package is composed correctly.
The different ways of how to install the library can be found here
Code improvements
Probably the least exciting improvement, but also one of the most important is the extend to which CmdMessenger has been refactored. We have made huge improvements on the .NET CmdMessenger library. The previous version of the .NET library relied on polling for new data to be available, which resulted in a trade-off between system load and responsiveness, that was never really satisfying. This update uses inter-thread signalling which is faster, less resource hungry and is much more elegant. A range of other improvements where made as well: improved thread safety, separation of concerns and more. Fun fact: The code has been running 24/7 on a test system without issues. In fact, this system was a Linux + Mono setup. This brings us to the next point:
Linux compatibility
While we stated in the previous releases that the .NET library was MONO compatible and therefore *SHOULD* run on Linux, this had not been tested. Now Valeriy did! One thing to note is that under Mono on Linux GetPortNames() will never show Arduino ports, so we added our own implementation.
Visual Basic samples
Vb Serial Port Read
It was always possible to use the CmdMessenger library in Visual Basic. However, being no Visual Basic user myself (and, honestly, not a very big fan of the language), I’ve never added examples. However, I have been asked a lot of question on how to use CmdMessenger in Visual Basic, so on a rainy evening I decided to bite the bullet and translate all examples to Visual Basic. So, after combining the result of 2 automatic C#-to-VB translators, following ReSharper suggestions and some of manual refactoring, we now have VB versions of all samples:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 | FriendEnum CommandIDs SetLed' Command to request led to be set in specific state Private_serialTransport AsSerialTransport Private_ledState AsBoolean ' Setup function _ledState=False ' Create Serial Port object _serialTransport.CurrentSerialSettings.PortName='COM6'' Set com port _serialTransport.CurrentSerialSettings.BaudRate=115200' Set baud rate ' Initialize the command messenger with the Serial Port transport layer _cmdMessenger=NewCmdMessenger(_serialTransport,BoardType.Bit16) ' Start listening EndSub ' Loop function ' Create command Dimcommand=NewSendCommand(CommandIDs.SetLed,_ledState) ' Send command Console.WriteLine(If(_ledState,'on','off')) ' Wait for 1 second and repeat _ledState=Not _ledState' Toggle led state |
Vb Net Bluetooth Serial Portable Speaker
AutoConnect & Watchdog
The Library now comes with an connection manager that you could use: It will scan all serial ports present (in the case of a serial connection), and try them at different speeds. If a serial port responds with the correct answer, the connection is confirmed.
Once the connection is confirmed, a watchdog can be started to monitor the connection. If the connection is silent for too long, the watchdog will ask the connected device for a sign of life. If no response comes, the connection manager will eventually take over and start scanning again. All This makes it very easy to set up and maintain connections.
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 | // You want to be sure you are connecting with the correct device. // Identify your device, for example, by using a GUID privateconststringCommunicationIdentifier='BFAF4176-766E-436A-ADF2-96133C02B03C'; ... { _transport=newSerialTransport(); // This is a 16-bit Arduino board _cmdMessenger=newCmdMessenger(_transport,BoardType.Bit16); // The Connection manager is capable or storing connection settings, in order to reconnect more quickly varserialConnectionStorer=newSerialConnectionStorer('SerialConnectionManagerSettings.cfg'); // Configure the connection manager _transport asSerialTransport,// Transport layer (int)Command.Identify,// Command to ask Arduino for identification serialConnectionStorer)// Storage functionality WatchdogEnabled=true,// Enable watchdog functionality. _connectionManager.Progress+=(sender,eventArgs)=> Console.WriteLine(eventArgs.Description); _connectionManager.ConnectionFound+=(sender,eventArgs)=> Console.WriteLine('Connected!'); _connectionManager.ConnectionTimeout+=(sender,eventArgs)=> Console.WriteLine('Disonnected!'); _connectionManager.StartConnectionManager(); ... |
Bluetooth
We have added a transport layer for Bluetooth, and tested expensively with the commonly used HC-05 and HC-06 breakout boards. The already existing serial interface will also work with these boards: if you set them up correctly (bind, enable virtual serial port), you can use the serial port to communicate.
We have gone a step further, though. By using the underlying RFCOM layer, the Bluetooth layer will not need an virtual serial connection and will immediately run on the correct speed, without overhead. Also, it allows for much nicer auto-connect behavior: Your Bluetooth device needs only be in range. The auto-connect code with search for both paired and unpaired devices. If unpaired, it will try the most commonly PIN codes to pair, and subsequently to connect.
Vb Net Bluetooth Serial Portal
The only thing you would have to do is connect your Arduino correctly to the HC-05/06 device, and make sure that the serial speed set in your script is the same as the speed set in your Bluetooth device (by default 9600, but this can be changed through the AT commands).
If you want, you can do more: have a look at this instructables manual and this very helpful guide . If you want to go in depth, have a look at the full AT command set here
Bluetooth Auto connect is very similar to the serial connection auto-connect functionality:
Vb.net Bluetooth Serial Port
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 | _transport=newBluetoothTransport() // If you know your bluetooth device and you have already paired // you can directly connect to you Bluetooth Device by adress. // Control Panel >> All Control Panel Items >> Devices and Printers // Right-click on device >> properties >> Unique id CurrentBluetoothDeviceInfo=BluetoothUtils.DeviceByAdress('20:13:07:26:10:08') varbluetoothConnectionStorer=newBluetoothConnectionStorer('BluetoothConnectionManagerSettings.cfg'); // The BluetoothConnectionManager will set up a connection for you. // - Auto discover Bluetooth devices // - If not yet paired, try to pair using the default Bluetooth passwords // - See if the device responds with the correct CommunicationIdentifier _transport asBluetoothTransport, (int)Command.Identify, bluetoothConnectionStorer) // Enable watchdog functionality. DevicePins= {'01:02:03:04:05:06','6666'}, }, // You can also add PIN code to try on all unpaired devices // (the following PINs are tried by default: 0000, 1111, 1234 ) { } |
New and updated samples
This version comes with some new & improved samples:
SimpleWatchdog
This example shows how to automatically find the correct serial-port and -speed, and monitor is the connection remains up.
SimpleBluetooth
This example shows all about discovering Bluetooth devices, pairing and connecting to them, as well as the watchdog functionality. Unfortunately this sample does not work with Bluetooth 4.0 (BLE) or under Linux.
Temperature control
The most extensive sample that came with the library was only usable for a limited number of users: only users with a relay switched heater, a thermocouple and a heatable basin where able to use it. We now added a simulated heater, which behaves as a real basin including heater and temperature measuring device. This is very nice if you like to play around with a remote controllable, PID regulated, heating solution without the hardware.