473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help A Fireman new to programming

14
First I am learning this as I go so please forgive my ignorance, all is self taught. I was given this as program to run an LED signboard for my fire station. The program is supposed to transmit the calls to the signboard so we can see what piece is due to go out the door. The problem is I am getting several warnings and also the program is sending multi-colors instead of just one. Any help is greatly appreciated.

betabrite.c In function main :
betabrite.c:88: warning: comparison between pointer and integer
betabrite.c:88: warning: comparison between pointer and integer
betabrite.c:93: warning: comparison between pointer and integer
betabrite.c:94: warning: passing arg 2 of 'write' makes pointer from integer without a cast
betabrite.c:96: warning: passing arg 2 of 'write' makes pointer from integer without a cast
betabrite.c:98: warning: comparison between pointer and integer
betabrite.c:100: warning: comparison between pointer and integer


Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6. #include <errno.h>
  7. #include <termios.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10.  
  11. #include "betabrite.h"
  12.  
  13. #define DEFAULT_SERIAL_PORT "/dev/com1" /* Cygwin */
  14.  
  15. int OpenPort(char *serial_port) {
  16.  
  17.    int fd ;
  18.  
  19.    fd = open(serial_port, O_RDWR|O_NOCTTY|O_NDELAY) ;
  20.  
  21.    if (fd == -1) {
  22.       perror("OpenPort: Unable to open port - ") ;
  23.    } else {
  24.       fcntl(fd,F_SETFL,0) ;
  25.    } /* if */
  26.  
  27.    return(fd) ;
  28.  
  29. } /* OpenPort() */
  30.  
  31. /* SetupSerial() - open the serial port and setup comm parameters */
  32.  
  33. int SetupSerial(char *serial_port) {
  34.  
  35.    struct termios options ;
  36.  
  37.    int fd = OpenPort(serial_port) ;
  38.  
  39.    tcgetattr(fd,&options) ;
  40.  
  41.    /* 9600 baud */
  42.  
  43.    cfsetispeed(&options,B9600) ;
  44.    cfsetospeed(&options,B9600) ;
  45.  
  46.    options.c_cflag |= (CLOCAL|CREAD) ;
  47.  
  48.    tcsetattr(fd,TCSANOW,&options) ;
  49.  
  50.    /* 7 bits */
  51.  
  52.    options.c_cflag &= ~CSIZE ;
  53.    options.c_cflag |= CS7 ;
  54.  
  55.    /* even parity */
  56.  
  57.    options.c_cflag |= PARENB ;
  58.    options.c_cflag &= ~PARODD ;
  59.    options.c_cflag &= ~CSTOPB ;
  60.    options.c_cflag &= ~CSIZE ;
  61.    options.c_cflag |= CS7 ;
  62.  
  63.    /* software flow */
  64.  
  65.    options.c_iflag |= (IXON | IXOFF | IXANY) ;
  66.  
  67.    options.c_oflag &= ~OPOST;
  68.    options.c_oflag &= ~ONLCR;
  69.    options.c_oflag &= ~OCRNL;
  70.  
  71.    tcsetattr(fd,TCSANOW,&options);
  72.  
  73.    return(fd) ;
  74.  
  75. } /* SetupSerial() */
  76.  
  77. int main(int argc, char **argv) {
  78.  
  79.     int fd;
  80.     int n;
  81.     char *serial_port = DEFAULT_SERIAL_PORT;
  82.  
  83.     fd = SetupSerial(serial_port) ;
  84.  
  85.     n = write(fd,"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",20) ;
  86.     n = write(fd,"\001Z00\002",5);
  87.  
  88.     if(argv[1] == 'a' && argv[2] == 'a')
  89.         n = write(fd,"A0",2);
  90.     else {
  91.         n = write(fd,"A0\x1B ",3);
  92.  
  93.         if(argv[2] == 'f')
  94.             n = write(fd,'c',1);
  95.         else
  96.             n = write(fd,'a',1);
  97.  
  98.         if(argv[1] == 'g')
  99.             n = write(fd,"\x1C\x32",2);
  100.         else if(argv[1] == 'r')
  101.             n = write(fd,"\x1C\x31",2);
  102.         else
  103.             n = write(fd,"\x1C\x38",2);
  104.  
  105.         n = write(fd,argv[3],strlen(argv[3]));
  106.     }
  107.  
  108.     //n = write(fd,"AA\x1B b",5);
  109.     //n = write(fd,"\x1C\x32\x13",3);
  110.  
  111.     n = write(fd,"\004",1);
  112.     close(fd);
  113.  
  114.     return(0);
  115. }
Feb 18 '09 #1
14 2720
donbock
2,426 Expert 2GB
The errors for lines 88, 93, 98, and 100 refer to improper use of argv. You need to tell us how you want your program to use command line arguments before we can suggest how to change this.

The errors for lines 94 and 96 refer to an improper call to the 'write' function. Notice that on line 91 the second argument to 'write' is enclosed in double quotes, but on lines 94 and 96 you enclose the second argument in single quotes. If you intend to write single characters on lines 94 and 96 then simply change the single quotes to double quotes.
Feb 18 '09 #2
pgfdbug
14
lines 94 and 96 are used to define how the message is displayed on the board the "a" is flash and "c" is scrolling. Lines 98 and 100 are used to define the colors. To run the program it comes up as ./betabrite g g "message here"
Feb 18 '09 #3
donbock
2,426 Expert 2GB
@pgfdbug
You should always check the value of argc before looking at the argv array. Somebody might have slipped up and left out an expected command line argument.

The argv array contains pointers to strings; so you have to perform string comparisons rather than single-character comparisons. For example,
Expand|Select|Wrap|Line Numbers
  1. if (strcmp(argv[1],"a") == 0)
instead of
Expand|Select|Wrap|Line Numbers
  1. if (argv[1] == 'a')
Personally, I find strcmp counterintuitive for string equality. Usually I define the following macro:
Expand|Select|Wrap|Line Numbers
  1. #define streq(s1,s2)    (strcmp(s1,s2) == 0)
as in
Expand|Select|Wrap|Line Numbers
  1. if (streq(argv[1],"a"))
Feb 18 '09 #4
pgfdbug
14
Is the line of code you gave me below used to replace all argv instances?

Expand|Select|Wrap|Line Numbers
  1. if (strcmp(argv[1],"a") == 0)
Feb 18 '09 #5
donbock
2,426 Expert 2GB
@pgfdbug
Well, you need to match the array index and literal string to what you already have; plus line 88 is a Boolean expression involving two string comparisons. But yes, something very much like this example should replace all places where you were comparing an argv to a character constant.
Feb 18 '09 #6
pgfdbug
14
I tried to implement the; #define streq(s1,s2) (strcmp(s1,s2) == 0); but i believe Im using it all wrong. It through up more errors than the before. Thank you for the suggestion but it is a little too advanced for my limited knowledge.
Feb 18 '09 #7
JosAH
11,448 Expert 8TB
@pgfdbug
Remove that trailing semi colon from your macro definition so that streq(x, y) will be replaced by (strcmp(x, y) == 0) by the C preprocessor.

kind regards,

Jos
Feb 19 '09 #8
pgfdbug
14
I tried the strcmp it removed all the errors but I still have the color problem. Lines 98-103 are what define the colors. Instead of one color as the message scrolls it puts out a different color every time.
Feb 19 '09 #9
Banfa
9,065 Expert Mod 8TB
Are you getting all the letters of your message? Is there any pattern to the colour of the letters?

It might help if you could tell us the exact make and model of your LED display sign.
Feb 19 '09 #10
pgfdbug
14
Its a betabrite LED 213C-1 is model. There is no pattern to the colors and I get the whole message with a 2 on the front of it. Below is a link to programming info.

http://wls.wwco.com/ledsigns/alpha/led97088061.doc
Feb 19 '09 #11
pgfdbug
14
sorry its a 1040 model
Feb 19 '09 #12
Banfa
9,065 Expert Mod 8TB
OK, from the document you posted pages 15 - 16 then here

Expand|Select|Wrap|Line Numbers
  1.          n = write(fd,"A0\x1B ",3);
  2.  
  3.          if(argv[2] == 'f')
  4.              n = write(fd,'c',1);
  5.          else
  6.              n = write(fd,'a',1);
  7.  
you have missed out the Display Position character that should come between the 0x1B and the Mode Code ('c' or 'a').

You are getting a 2 because 0x32 is the character '2', I don't know why you are getting multi-colours but the malformed message should be fixed first.


Finally on a separate note if argv[1] == "a" and argv[2] == "a" you don't output the text because you have the } in the wrong place.
Feb 19 '09 #13
pgfdbug
14
Thank you all for all your help it turns out it was the position code that messed it all up. It took me a year but its all fixed. If any of you have some time and want to give me some more help with some bugs let me know.
Feb 19 '09 #14
Banfa
9,065 Expert Mod 8TB
No problem. You are always welcome to start a new thread for any further programs you are having, or to continue this one.
Feb 19 '09 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
4
by: Weasel | last post by:
Hey everyone, My names John and i just recently joined this googl group, and I joined because i need some help. I'm currently a Sophomore in High school and i'm really interested in computer...
27
by: SK | last post by:
Hi I am trying to teach myself how to program in C. I am a physician hoping to be able to help restructure my office. Anyhow, I amhoping that the porblem I am having is simple to those much more...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: Joel Fireman | last post by:
Help Needed: Upgrade Fedora 4 / Apache 2 to PHP 5.2.x from 5.0.4 I've been testing Joomla as a content manager for the County offices, and it looks pretty good. Unfortunately, I decided to...
3
by: Ken Foskey | last post by:
I am a new VS and C# developer with 20 plus years programming experience and I am finding the database stuff incredibly frustrating. I have read programming c# 3.0 pretty much cover to cover, ...
11
by: pgfdbug | last post by:
Below is the code for the program that runs my firehouses alerting system. It reads packets that come to our printer and gives us an audible alert on what piece is due. The two issuse I have with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.