MOU AL202 Linux Null Characters

Support for MOC/MOS/MOI/MOU/X-Board/MOP

Moderator: Mods

Post Reply
AlmightyJu
LCD?
Posts: 2
Joined: Mon Nov 22, 2010 10:24 am

MOU AL202 Linux Null Characters

Post by AlmightyJu » Mon Nov 22, 2010 1:25 pm

Hi,

I've just switched over to using Linux and am having some problems making a program to control my screen, i made a program in .net on windows and it works without an issue, so i dont know if its a c++ issue or Linux. This is my first go at c++ so wouldn't be surprised if i'm missing something!

I dont know if anyone could look at the attachments and help me work out whats happening? I've tried reading all sorts and cant get anywhere and get the same problem with Python and perl.

Basically when sending commands such as 0xFE, 0x58 to clear the screen it will clear but sending another command after wont work or if i send a string it seems to drop the first character. If i send nulls after a command it seems to work but leaves some strange character behind.

The picture with the X in the bottom row is without sending nulls and the other picture with the strange character is with sending nulls, both from sending a test string, sending the turn on command and then clearing the screen.

The other picture is from not sending nulls but sending the string, turning the screen on, sending the string again.

I cant seem to see whats going on so any help would be great!

Thanks,
Julian
Attachments
main.cpp
C++ code
(2.36 KiB) Downloaded 203 times
2010-11-22 17.12.05.jpg
With nulls
2010-11-22 17.12.05.jpg (92.01 KiB) Viewed 3357 times
2010-11-22 19.34.07.jpg
without nulls
2010-11-22 19.34.07.jpg (99.15 KiB) Viewed 3356 times
2010-11-22 19.57.23.jpg
no nulls but string between commands
2010-11-22 19.57.23.jpg (99.21 KiB) Viewed 3356 times

Clark
Matrix Orbital
Matrix Orbital
Posts: 856
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Post by Clark » Wed Nov 24, 2010 9:59 am

Hi Julian,

I think a command is going awry somewhere here. Can you post your turn on command?

It looks like the little things are taken care of, but I'll post them just in case they trigger a memory. Data is 8 bits, no parity, one stop bit. Handshaking is turned off. I like to use the byte data type to ensure commands are sent correctly rather than transmitted as text.

Finally, if you're curious, the X is of course hex 58, the clear screen command byte, and the strange symbol is the top left corner of our logo from the start screen. This character appears when the display receives a 0 value.

Thanks,
~Troy
Troy Clark
Design & Development
Matrix Orbital

AlmightyJu
LCD?
Posts: 2
Joined: Mon Nov 22, 2010 10:24 am

Post by AlmightyJu » Wed Nov 24, 2010 12:10 pm

Hi Troy,

The commands I send as bytes since it makes more sense to me, i could understand the X but I'd never seen the logo character since I changed the start screen so now i know :)

The relevant bits of code are:

Code: Select all

void turn_on_screen(){
    cout << "Turning on screen press ENTER to continue";
    unsigned char d[] = {0xFE, 0x42, 0};
    sendData(arrayToVector(d, 3));
}

vector <unsigned char> arrayToVector(unsigned char *a, int size){
    vector <unsigned char> r;
    for(int i=0; i<size; i++) r.push_back(a[i]);
    return r;
}

unsigned char* vectorToArray(vector <unsigned char> v){
    unsigned char* r = (unsigned char*) malloc(v.size());
    for(int i=0,c=v.size();i<c;i++) r[i]=v[i];
    return r;
}

void sendData(vector <unsigned char> data){
    unsigned char* r = vectorToArray(data);
    int rs = write(Screen, r, data.size());
    free(r);
    tcdrain(Screen);
    cin.ignore();
}
I know it seems a bit backwards going back and for vectors and arrays so I tried it with just consecutive write(Screen, command, 3); and get the same result.

Thanks,
Ju

Clark
Matrix Orbital
Matrix Orbital
Posts: 856
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Post by Clark » Mon Nov 29, 2010 2:01 pm

Hi Ju,

I appreciate the code, did look at it, but we are moving so I must apologize for the tardiness of my response.

I will preface this by stating it's been years since I wrote or graded C++, but that code has me thinking there must be a better way; it is more than likely the source of your trouble. We don't have a C++ example like we do for C#, so I hacked and slashed my way through some code that works and have attached it. I am no professional, I have not added comments yet, please use at your own risk, but know my computer is still in one piece sans flames.

Have a look at simplifying your write statements, and let me know if you have any questions or concerns regarding the attached.

Thanks,
~Troy
Attachments
Hello World C++.cpp
Sample Hello World Program in C++ with Commands
(1.33 KiB) Downloaded 242 times
Troy Clark
Design & Development
Matrix Orbital

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest