Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Simple Serial - An easy-to-use serial communications plugin for DBPro

Author
Message
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 2nd Jan 2015 13:41 Edited at: 2nd Jan 2015 13:50
Hey all

---------------------------------------------------------------------------------------
Introduction
---------------------------------------------------------------------------------------

I haven't made any new plugins recently, but I received my Arduino Uno board about a week ago, and since I also bought an MPU-6050 motion sensor on a GY-521 breakout board (for all of $5 on eBay), I wanted to get my Arduino communicating with DBPro so I could easily display a 3D object that rotated according to the angle of the physical chip. This resulted in quite a bit of Googling because I knew virtually nothing about serial communication, but the end result is Simple Serial. It's basically a wrapper for the surprisingly minimalistic code from here, so I can't and don't claim credit for most of the actual serial code, but I did make a few modifications for extra functions and flexibility

The plugin is designed primarily for easy communication with Arduinos, so there's a few default values that are best suited to that purpose, however everything can be changed to communicated with most any serial device. As far as I know it doesn't support opening more than one channel of communication at a time, and believe if you try you'll either get errors or end up with memory leaks

Full source code is included. To compile, you'll have to add C:\Program Files (x86)\Microsoft DirectX SDK (August 2007)\Include as an additional include directory (which obviously means you need to have downloaded and installed the August 2007 version of the DX SDK). You'll also have to add the directories containing the standard DBPro files (like globstruct.h, DBOData.h and global.h), all of which can be found in the Extras folder in your DBPro install directory. Additionally, you will need to add the C:\Program Files (x86)\Microsoft DirectX SDK (August 2007)\Lib\x86 folder to the additional library directories. You'll need Visual Studio C++ 2008 to compile.

If you just want to use the DLL, extract the Compiler and Editor folders straight into your DBPro install directory and restart DBPro

A readme is included as simple documentation, but I'll repeat the instructions here.


---------------------------------------------------------------------------------------
List of commands
---------------------------------------------------------------------------------------

SERIAL SET ARDUINO WAIT TIME==WaitTime
Not sure how useful this is, but it's here nonetheless. All it does is set (in milliseconds) how long the SERIAL OPEN command should wait before returning, to give the Arduino time to restart. Just set this to 0 if you don't want a 2-second pause when you call SERIAL OPEN Defaults:
WaitTime: 2000

SERIAL OPEN==[Port$][Port$, BaudRate][Port$, BaudRate, ByteSize, StopBits, Parity]
Call like this: serial open "COM3" Defaults:
BaudRate: 9600
ByteSize: 8
StopBits: 0
Parity: 0
Valid options are (for more specific data, look in WinBase.h, which is a standard Windows include file AFAIK):
BaudRate:

ByteSize: Anything, presumably.
StopBits:

Parity:


SERIAL CLOSE==*no parameters*
Should make it safe to call SERIAL OPEN again. Untested.

SERIAL IS CONNECTED==(*no parameters*)
Use this to detect if the attempted connection was successful.

SERIAL DATA AVAILABLE==(*no parameters*)
Returns how many bytes (if any) are sitting in the buffer, waiting to be read. If none, returns 0.

SERIAL READ STRING==(Bytes)
Reads an array of bytes in the form of a string. Good for getting lots of data at once. Will attempt to retrieve the number of bytes set with the parameter Bytes. If there are not enough available, will return as many as possible.

SERIAL READ BYTE==(*no parameters*)
Reads just one byte at a time.

SERIAL WRITE STRING==(Data, Bytes)
Sends a string as an array of bytes. Set Bytes to the number of characters in the string. Possibly also needs to be length+1 for null-terminated strings. Returns number of bytes successfully sent.

SERIAL WRITE BYTE==(Data)
Sends a single byte. Also returns number of bytes successfully sent, but since there's only one byte, will only return 0 (unsuccessful) or 1 (successful).

SERIAL GET LAST ERROR==(*no parameters*)
Returns a number referring to one of the following error values (again, from WinBase.h):



---------------------------------------------------------------------------------------
Example usage
---------------------------------------------------------------------------------------




---------------------------------------------------------------------------------------
Download
---------------------------------------------------------------------------------------

2015/01/02 - V1.0 - Current

That's all for now. If you need any help with this or find a bug, don't hesitate to reply here

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-25 14:56:42
Your offset time is: 2024-04-25 14:56:42