Google Answers Logo
View Question
 
Q: computer programing ( No Answer,   6 Comments )
Question  
Subject: computer programing
Category: Computers
Asked by: ladyalice-ga
List Price: $25.00
Posted: 17 Aug 2004 06:21 PDT
Expires: 16 Sep 2004 06:21 PDT
Question ID: 388923
I need to control a relay (R2 dual relay controller) via the serial
port using CB86 (CBasic)I have the code in QBasic and VB but I can't
find anything for CBasic code.
This is the Cbasic code I have tried. It succcessfully opens the
serial port but it does not sent the  chr$(252);chr$(0)( turns on
relay) which is needed to call the relay or chr$(252);chr$(1)(turns on
relay)

%include extfun
%include mstools
%include cbonly
on error goto bad
re1%=mbexec("c:\winnt\system32\command.com","/c mode.com com1:
baud=9600 data=8>nul")
re1%=mbexec("c:\winnt\system32\command.com","/c mode.com lpt1:=com1:>nul")	

st:	print cscr$
	print
	print "control relay"
	print
	print
	input "Hit <enter> to activate relay ";line p$
	print

print chr$(254),chr$(1)
az=inkey
print chr$(254),chr$(0)

	input "Try again  ? Y/N ";line as$
	if ucase$(as$)="N" then stop
	goto st

bad:	call errors("")

Clarification of Question by ladyalice-ga on 02 Sep 2004 11:54 PDT
cythias=ga
Yes I did change CAT to TYPE thanks
I tried the following didn't work !!!! 



%include extfun
%include mstools
%include cbonly

on error goto bad

	re1%=mbexec("c:\winnt\system32\command.com","/c mode.com com1: baud=9600 data=8")

	re1%=mbexec("c:\winnt\system32\command.com","/c mode.com lpt1:=com1:")	


	re1%=mbexec("c:\winnt\system32\command.com","/c print relayon.txt > com1")


	re1%=mbexec("c:\winnt\system32\command.com","/c print relayoff.txt > com1:")	


bad:	call errors("")


files

-----------------------------------------------

relayon.txt     chr$(254);chr$(1)

relayoff.txt    chr$(254);chr$(0)

-----------------------------------------------

I also tried

relayon.txt     ?;1

relayoff.txt    ?;0
Answer  
There is no answer at this time.

Comments  
Subject: Re: computer programing
From: 1anton1-ga on 17 Aug 2004 10:17 PDT
 
Could this be because you are sending:

print chr$(254),chr$(1)

instead of:

print chr$(252);chr$(1)

Or was that just a typo in your question ?
Subject: Re: computer programing
From: crythias-ga on 17 Aug 2004 12:21 PDT
 
http://shorterlink.com/?J26PTE This should give a hint. If you OPEN AS
#1, you can Print #1, character..

Re: the above comment: be aware that "," may send a tab character
between CHR$'s. The ";" context is better for your project.
Subject: Re: computer programing
From: crythias-ga on 17 Aug 2004 12:30 PDT
 
if you can't open the com port with your cbasic, you already have
mbexec. Just make two files relayon.txt and relayoff.txt, each with
the two characters you need.

then mbexec("c:\winnt\system32\command.com","/c cat relayon.txt >
com1") or mbexec ("c:\winnt\system32\command.com","/c cat relayoff.txt
> com1")

Also, according to your question... it seems you need to swap 0 and 1. 

Likewise, PRINT and INPUT will go both to screen unless they're going
both to com1. You can't have it both ways :). I'm guessing that "Try
again ?" is a user input on the screen, not control information that
will be displayed on the relay.
Subject: Re: computer programing
From: tidlick1-ga on 29 Aug 2004 17:51 PDT
 
What operating system are you using ??
This governs wether data can be input/output from the data ports
Subject: Re: computer programing
From: crythias-ga on 31 Aug 2004 06:13 PDT
 
instead of "cat" you might use "type" for Windows/DOS. Oops. Sorry :).
Subject: Re: computer programing
From: crythias-ga on 02 Sep 2004 12:22 PDT
 
DOS prompt. edit relayon.txt
alt (numberpad 254, numberpad001)

no semicolons :)
Save, exit. see if that works.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy