Our new official repo is on github
LCD Smartie version 5.6 is released!
Download it now: https://github.com/LCD-Smartie/LCDSmartie/releases

VFD Driver C++ Framework initial parameter

Discussing issues that occur during plugin development.

Moderators: _X7JAY7X_, caesar, IFR, mattcro, limbo

Post Reply
djkoyanagi
Posts: 4
Joined: December 17th, 2007, 4:40 am

VFD Driver C++ Framework initial parameter

Post by djkoyanagi »

Noob question:

I've seen this post but I'm still confused.
http://forums.lcdsmartie.org/viewtopic. ... t+position

In this initial parameter function:

DLL_EXPORT(char *) DISPLAYDLL_Init(LCDS_BYTE size_x,LCDS_BYTE size_y,char *startup_parameters,LCDS_BOOL *ok) {


*ok=1;
return NULL;
}

i would like to set:
size x: 20
size y: 4
startup parameter: COM3,38400,8,N,1
LCDS_BOOL: 1

On Set position function

DLL_EXPORT(void) DISPLAYDLL_SetPosition(LCDS_BYTE x,LCDS_BYTE y) {
}

Set to:
x: 0
y: 0

Could someone please rewrite/fill in the function and brief comment so i can see how this is done?

Thank you

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

You shouldn't set the parameters inside the display driver DLL (except for initial debugging if you don't have any parameter parsing code). Smartie gives the driver these parameters (which are whatever the user sets in the Setup window).

So DISPLAYDLL_Init() gets these parameters passed to it, and it has to separate out the required info from the parameter string *startup_parameters and use it (and the other parameters) to initialise the display - configure/open the serial/USB port etc, and write the initialisation commands to the display.

If you're just starting to develop a driver, you can temporarily manually specify fixed parameters (ie ignore the Smartie parameters) in the Init function. Exactly how you do this depends on what type of port etc you are using.

For example, to manually set parameters using the SerialPort class in VC.NET 2005:

Code: Select all

comPort = new Ports::SerialPort();
comPort->BaudRate=9600;
comPort->PortName="COM2";
comPort->DataBits = 8;
comPort->Parity = Ports::Parity::None;
comPort->StopBits = Ports::StopBits::One;

//Open serial port
comPort->Open();
LCDS_BOOL *ok is the boolean flag that the display driver uses to tell Smartie whether it successfully initialised the display or not. When initialisation is complete, DISPLAYDLL_Init sets *ok=1.

You can suggest default parameters to the user (these will appear in the Setup window) using the DISPLAYDLL_DefaultParameters function. Smartie calls this when you select the driver, and the function should return a char array (basically a string) containing the default parameters - "COM3,38400,8,N,1" in your case. Then the user can just click OK in the Setup window to use those parameters.

Example (the driver assumes 8,N,1 serial so you only specify the port and baud rate):

Code: Select all

DLL_EXPORT(char *) DISPLAYDLL_DefaultParameters(void)
{
	static char plugin_default_parameters[]="COM1,19200";
	return plugin_default_parameters;
}
The DISPLAYDLL_SetPosition function is used by Smartie to set the LCD cursor position to whatever Smartie needs when it is writing to the display. Again, you shouldn't simply set the position to 0,0 in this function - that will mess up the displayed text because Smartie wants to set the position as needed. This function should send the appropriate commands to the display to set the cursor to the required position (calculated from the x and y parameters).

See my driver plugin , Nick's FTDI USB driver and Rick's SparkFun driver using this framework for more examples.

Phew! I hope you get some use out of all that. This programming business can be very confusing to start with...

djkoyanagi
Posts: 4
Joined: December 17th, 2007, 4:40 am

Setting the Default Display Position

Post by djkoyanagi »

mattcro thank you for your reply, it was very informative.

what variable/function in C++ is used to set the position of the line 1-4 in LCD smartie ?

I would like to set gotoLine1, gotoLine2, gotoLine3 and gotoLine4 under DISPLAYDLL_SetPosition() parameter.

If that's not possible how would i write in C/C++ the default position if my display position starts with:
line 1: x=0 y=0
line 2: x=0 y=1
line 3: x=0 y=2
line 4: x=0 y=3

The display size is 4x20

Thank you and please let me know if you need more information

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

I assume you're developing a new driver to use an LCD module of some sort with Smartie? If so, give us some more info on the LCD, connection method etc. If not, let us know what you're trying to achieve.

Basically all the display driver does is translate standardised commands from Smartie (like "go to line 3 character 10", or "write this string to the display") into the specific commands for the particular LCD. So your driver functions such as DISPLAYDLL_SetPosition() are just supposed to do what Smartie asks.

If you already know that, don't worry. It just sounds like you are trying to do something that the driver isn't intended for. You're not expected to set things like communications (serial port) parameters to specific values in the driver itself. Smartie tells your driver what parameters/data it wants to send to the LCD and your driver sends the appropriate commands for your particular LCD.

For example, if Smartie wants to move the cursor (the text entry point) on the LCD to the beginning of the 2nd line, it will call your driver function like so:

Code: Select all

DISPLAYDLL_SetPosition(1,2)
(Note that 1,1 is the top left)

Your driver has to do something like calculate the appropriate address in display memory (for a standard HD44780 type LCD) or convert x=1 and y=2 into the appropriate command to set the position, and send that command to the LCD.

For example, my JW-002 driver does all this:

Code: Select all

DLL_EXPORT(void) DISPLAYDLL_SetPosition(LCDS_BYTE x,LCDS_BYTE y)
{
	unsigned char lcd_x, lcd_y;
	lcd_x = x - 1;    //LCD uses 0,0 as top-left
	lcd_y = (y - 1) * 2;
	if (x > 20)  //if more than halfway across the Smartie display area
	{
		//split lines in the middle and treat right-hand half as the next line
		lcd_y += 1;
		lcd_x -= 20;
	}
	sprintf(outputBuffer, "\\B%c%c", lcd_x+32, lcd_y+32);  //generate the "set cursor" command string
	serialWrite(outputBuffer);  //send command string to serial port
}
Exactly what you need to send depends entirely on the particular LCD controller (that's what the driver is all about), but you basically translate Smartie's commands into whatever your LCD understands and transmit the result to the LCD, and nothing else.

There's no standard way to talk to an LCD in C (or any other language). You have to write the code to suit the particular LCD and connection method (eg serial, parallel or USB port) you use. That's what the driver is for.

I suspect that wasn't very well explained, so I hope I haven't confused you any further! :?

djkoyanagi
Posts: 4
Joined: December 17th, 2007, 4:40 am

Post by djkoyanagi »

I assume you're developing a new driver to use an LCD module of some sort with Smartie? If so, give us some more info on the LCD, connection method etc. If not, let us know what you're trying to achieve.
COM port:4
Baudrate: 38400
DataBits 8
handshake: RequestToSend
Parity: None
StopBits: 1

screen size 4x20

Objective: I would like to create a driver for this VFD but there are few problems.
1. When writing on to the display, because of serial to USB converter, I can't write all 20 character at once, I would need to write one character at a time.
2. visual studio 2008 has serialport class, for display driver I would need to recreate that right? if so can i have the source code?
3.I would like to set the brightness control.1 = 12.5%,2=25%,3=37.5%,4=50%,5=62.5,6=75%,7=87.5%,8=100%
4. How does LCD smartie interact with these classes?

Initially i just want to create a driver that will set the initial setup, default parameter, set the driver name, cursor positioning, write without the glitch and set the brightness control

if you have a source code i can use I greatly appreciated


Thank you

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

First things first: Check the forums to make sure somebody hasn't already made a suitable driver. There might be a driver that works or something that can be adapted to your display (unless it's something really unusual!). What make/model is it?

I started developing an LCD driver for Smartie in VC++ 2005 .NET Express using the SerialPort class, but gave up on it in favour of non-NET code using the old-style Win32 APIs (requires Windows Platform SDK - free download from MS). I had used VC6 in the past and sort of knew my way around that, but I'm not too hot on some of the newer .NET classes etc, so can't help a lot with that. I can give you the beginnings of the VC++ 2005 project which might help. You can also look at the source code for any driver plugins on the forum.

For initial developing/debugging, you can hard-code the startup parameters in the driver, like I showed in the code snippet before. Once you have the driver basics working OK, it's best to configure the port (in DISPLAYDLL_Init) according to the parameters Smartie passes to the Init function. You might not always have the LCD connected to COM4, for example, so these parameters should not be hard-coded into the finished driver.

How is the display connected to the PC? I guess the VFD has an RS232 (serial port) interface and you are using a USB->RS232 adapter of some sort? In that case, you shouldn't need to worry about writing one character at a time. If the VFD can operate properly at 38400baud you shouldn't need any delays etc. If there is something in the VFD spec about delays between characters or commands, you'll need to figure a way to force delays where necessary - see Thread.Sleep().

Have you used the VFD with something else (other software etc) that causes glitches due to overloading the VFD processor with receive data? It could be that it simply requires handshaking signals, so if you set the serial port correctly, you don't need any delays between characters.

You can use RTS/CTS handshaking in the SerialPort class to control the data flow - you just set something like comPort->RtsEnable = true;. See the MSDN documentation for all the details.

You don't need to do anything much to use a serial port. You just create a new serial port object ( like so: comPort = new Ports::SerialPort();), configure it (like in my code snippet below), open it, and then write text to it like comPort->Write("A message");.

For the brightness control, use the DISPLAYDLL_SetBrightness() function. This actually sets the backlight brightness on LCDs, but is probably the best equivalent for VFD brightness. You'll need to translate the 0-255 brightness range into the 1-8 (or is it 0-8 ) levels for the VFD, so you can probably get away with just dividing the brightness by 32.

LCD Smartie doesn't really care what your driver does internally. That's why you can use various programming languages (C++/.NET, Delphi, C# etc). All Smartie cares about is that you provide (most of) the functions in the list you linked to.

At the bare minimum, you need: Init, Done, SetPosition and Write. DriverName and Usage are useful for the user. CustomChar and CustomCharIndex can be added later or left blank if you don't have custom character support on the display.

Well, another long post - hope you're making some progress!

djkoyanagi
Posts: 4
Joined: December 17th, 2007, 4:40 am

Post by djkoyanagi »

Thank you for all your help so far, it's very informative.

Newbie question

How can #include the .net framework class to this file? I'm using VS 2008 and writing in C++. I haven't used C++ in a while, I think alot of my problem can be resolve if i can use .net namespace; I just don't know how to reference the classes

Thank you

Post Reply