Device stops at midnight

0 pts.
Tags:
Visual Basic
I am using a 232SDA12 which is a data acquistion device from B&B Electronics. I am using the following VB code and for some reason it stops at midnight. What am I missing? '***************************************************************** ' File name: 232SDAXX.BAS ' Version: 2.00 ' Release Date: 12/09/06 ' Latest version for test. '***************************************************************** DECLARE SUB locate.module () DECLARE SUB Read.digital () DECLARE SUB pause (length!) DECLARE SUB Installports () DECLARE SUB waitchr () DECLARE SUB Tx (DataString$) DECLARE SUB select.mode () DECLARE SUB change.mode () DECLARE SUB Read.ad () DECLARE SUB Scan.dots () DECLARE SUB running.dots () DECLARE SUB check.keyboard () DECLARE SUB get.number () DECLARE SUB Set.Port () 'Define the global variables COMMON SHARED baud COMMON SHARED reading() 'Data read is stored here COMMON SHARED ch$ 'Used when reading keyboard COMMON SHARED Ref.plus, Ref.minus 'Reference Voltage values COMMON SHARED digital.states ' COMMON SHARED COM$, comport COMMON SHARED numsteps, bits 'A/D resolution COMMON SHARED j, number, help 'Misc. values COMMON SHARED Esc$, F1$, F2$, F3$, F4$, F12$, cnt, cnt2, voltage, cnt3, cnt4 CONST yes = 1 'Define yes CONST no = 0 'Define no DIM reading(10) baud = 9600 COM$ = "COM1" comport = 1 Ref.plus = 5 'Default Reference (+) Voltage Ref.minus = 0 'Default Reference (-) Voltage numsteps = 4096 bits = 12 Esc$ = CHR$(27) j = 0 'Initialize j to 0 cnt6(1) = -1 OPEN "O", #10, "c:stats.txt" CLS 'Clear Screen, display.info CLOSE #1: CLOSE #2 PORT$ = COM$ + ":9600,N,8,1,cd,ds,cs,rs" 'Sets up the serial port OPEN PORT$ FOR RANDOM AS #(comport) 'Installports pause (.5) 'Wait for power up locate.module 'Makes sure module is communicating states = states AND (NOT (7)) cmdString$ = "!0SO" + CHR$(states) CALL Tx(cmdString$) LOCATE 6, 1: PRINT SPACE$(80) DO COLOR 7, 0 LOCATE 5, 10 PRINT , " Voltage Engineering units " 'Set up Display Read.ad 'Read a/d FOR channel = 0 TO 10 'Data is returned in "reading" array LOCATE 10, 2 'PRINT TIME$ 'PRINT DATE$ LOCATE channel + 6, 15 'Display data in hex format PRINT "A/D Ch"; channel; 'HEX$(reading(channel)); voltage(channel) = reading(channel) * 5 / 4096 PRINT USING " #.###"; voltage(channel); 'Display voltage reading LOCATE 18, 65 PRINT "VENT" LOCATE 19, 65 PRINT "CLOSE" LOCATE 20, 65 PRINT "OPEN" engineerunits(0) = voltage(0) * 4 '0 - 5 volts = 0 to 20 volts engineerunits(1) = voltage(1) * 124.138 '0 - 5 volts = 0 to 610 millimeters engineerunits(2) = (voltage(2) * 290) - 100 '0 - 5 volts = -100?C to 1350?C IF voltage(10) > 1.5 THEN cnt = cnt + 1 IF cnt = 21195 THEN cnt2 = cnt2 + 1 IF cnt = 10 THEN states = states OR 2 IF cnt = 20 THEN states = states AND (NOT (2)) IF cnt = 6340 THEN states = states OR 1 IF cnt = 6350 THEN states = states AND (NOT (1)) IF cnt = 16850 THEN states = states OR 1 IF cnt = 16860 THEN states = states AND (NOT (1)) IF cnt = 21050 THEN states = states OR 2 IF cnt = 21060 THEN states = states AND (NOT (2)) IF cnt = 21200 THEN cnt = 0 IF cnt2 = 24 THEN states = states AND (NOT (7)) IF cnt2 = 24 THEN END IF cnt = 0 THEN states = states AND (NOT (7)) IF voltage(10) < 1.5 THEN cnt = 0 IF voltage(10) < 1.5 THEN states = states AND (NOT (7)) LOCATE 17, 60 PRINT "Cycle Count"; cnt2 LOCATE channel + 6, 50 IF voltage(channel) > 2 THEN COLOR 12, 0 PRINT USING "####.##"; engineerunits(channel) COLOR 7, 0 LOCATE 6, 58 PRINT "volts" LOCATE 7, 58 PRINT "mm" LOCATE 8, 58 PRINT "?C" LOCATE 13, 2 PRINT USING "#####"; cnt cmdString$ = "!0SO" + CHR$(states) CALL Tx(cmdString$) IF voltage(10) < 2 THEN Scan.dots 'Displays "Scanning........" IF voltage(10) > 2 THEN running.dots pause (.1) NEXT Read.digital mask = 1 mask2 = 8 FOR digital = 0 TO 2 LOCATE 18 + digital, 1 PRINT "Digital Output"; digital; IF mask AND digital.states THEN COLOR 2, 0 PRINT " ON"; COLOR 7, 0 ELSE COLOR 12, 0 PRINT " OFF"; COLOR 7, 0 END IF PRINT , "Digital Input"; digital; IF mask2 AND digital.states THEN cnt5(digital) = cnt5(digital) + 1 PRINT " HI" ELSE cnt5(digital) = 0 PRINT " LOW" END IF mask = mask * 2 mask2 = mask2 * 2 IF cnt5(digital) = 2 THEN cnt6(digital) = cnt6(digital) + 1 IF cnt5(digital) = 1000 THEN cnt5 = 5 LOCATE digital + 18, 55 PRINT INT(cnt6(digital)); NEXT check.keyboard 'Check for input from keyboard IF cnt > 21199 THEN WRITE #10, DATE$, TIME$, engineerunits(0), engineerunits(1), engineerunits(2), cnt6(0), cnt6(1), cnt6(2), cnt2 LOOP END 'This routine checks to see if a character has been typed. SUB check.keyboard ch$ = "" ch$ = INKEY$ IF LEN(ch$) > 0 THEN SELECT CASE ch$ CASE F1$ CASE F2$ toggle.state = (NOT digital.states) AND &H1 new.state = toggle.state OR (digital.states AND &HFE) cmdString$ = "!0SO" + CHR$(new.state) CALL Tx(cmdString$) CASE F3$ toggle.state = (NOT digital.states) AND &H2 new.state = toggle.state OR (digital.states AND &HFD) cmdString$ = "!0SO" + CHR$(new.state) CALL Tx(cmdString$) CASE F4$ toggle.state = (NOT digital.states) AND &H4 new.state = toggle.state OR (digital.states AND &HFB) cmdString$ = "!0SO" + CHR$(new.state) CALL Tx(cmdString$) CASE F12$ states = (NOT digital.states) AND (NOT (7)) cmdString$ = "!0SO" + CHR$(states) CALL Tx(cmdString$) CASE Esc$ states = states AND (NOT (7)) cmdString$ = "!0SO" + CHR$(states) CALL Tx(cmdString$) CLOSE #(comport) CLOSE #1, 10 'SHELL "COPY d:stats.txt c:stats.txt" END CASE ELSE LOCATE 6, 1: PRINT SPACE$(80) j = 0 END SELECT END IF END SUB 'This routine is used to read in a number from the user. ' SUB get.number CONST true = -1 CONST false = 0 sign = 1 Numeral$ = "" Decimal.Flag = true DO waitchr SELECT CASE ch$ CASE "0" TO "9" number$ = number$ + ch$ PRINT ch$; CASE "." IF Decimal.Flag = true THEN number$ = number$ + ch$ PRINT ch$; Decimal.Flag = false ELSE BEEP END IF CASE "," PRINT ch$; CASE "-" IF LEN(number$) = 0 THEN PRINT ch$; sign = -1 ELSE BEEP END IF CASE CHR$(13) EXIT DO CASE ELSE BEEP END SELECT LOOP number = VAL(number$) * sign END SUB SUB locate.module LOCATE 5, 10: PRINT "Attempting to locate module...." junk$ = INPUT$(LOC(comport), #(comport)) 'Clear Receive Buffer ReadString$ = "!0RD" CALL Tx(ReadString$) 'Transmit read string 'The next DO LOOP checks to make sure the 232SDAxx is responding. t# = TIMER 'Get current time DO 'Begin DO LOOP IF LOC(comport) = 1 THEN EXIT DO 'Wait for complete string IF TIMER > t# + .5 THEN 'Indicate possible problem BEEP LOCATE 21, 1 PRINT "The 232SDAxx is not responding" PRINT "Enter a anykey to continue" waitchr EXIT SUB END IF LOOP junk$ = INPUT$(LOC(comport), #(comport)) END SUB SUB pause (length) Start = TIMER DO IF Start + length < TIMER THEN EXIT DO LOOP END SUB 'This subroutine gets the data from the 232SDAXX. The data is returned 'in the variable "reading" array. SUB Read.ad junk$ = INPUT$(LOC(comport), #(comport)) 'Clear Read BUffer ReadString$ = "!0RA" + CHR$(10) CALL Tx(ReadString$) 'Transmit read string 'The next DO LOOP checks to make sure the 232SDAXX is responding. t# = TIMER 'Get current time DO 'Begin DO LOOP IF LOC(comport) = 22 THEN EXIT DO 'Wait for complete string IF TIMER > t# + .5 THEN 'Indicate possible problem BEEP LOCATE 21, 1 PRINT "The 232SDAXX is not responding" PRINT "Enter a anykey to continue" ferror = yes waitchr EXIT SUB END IF LOOP FOR i = 10 TO 0 STEP -1 inbyte = ASC(INPUT$(1, #(comport))) MSB = inbyte * 256 LSB = ASC(INPUT$(1, #(comport))) reading(i) = MSB + LSB NEXT END SUB SUB Read.digital junk$ = INPUT$(LOC(comport), #(comport)) 'Clear Read BUffer ReadString$ = "!0RD" CALL Tx(ReadString$) 'Transmit read string 'The next DO LOOP checks to make sure the 232SDAxx is responding. t# = TIMER 'Get current time DO 'Begin DO LOOP IF LOC(comport) = 1 THEN EXIT DO 'Wait for complete string IF TIMER > t# + .5 THEN 'Indicate possible problem BEEP LOCATE 21, 1 PRINT "The 232SDAXX is not responding" PRINT "Enter a anykey to continue" ferror = yes waitchr EXIT SUB END IF LOOP digital.states = ASC(INPUT$(1, #(comport))) END SUB SUB running.dots IF j = 70 THEN j = 0 ELSEIF j = 0 OR j = 1 THEN LOCATE 21, 1: PRINT "RUNNING"; SPACE$(70) 'COLOR 7, 0 ELSE LOCATE 21, 8 + j: PRINT "." END IF j = j + 1 END SUB SUB Scan.dots IF j = 70 THEN j = 0 ELSEIF j = 0 OR j = 1 THEN LOCATE 21, 1: PRINT "Scanning"; SPACE$(70) ELSE LOCATE 21, 8 + j: PRINT "." END IF j = j + 1 END SUB SUB Tx (DataString$) PRINT #(comport), DataString$; END SUB 'This routine wait for input from the user. SUB waitchr ch$ = "" WHILE LEN(ch$) = 0 ch$ = INKEY$ WEND IF ASC(ch$) = 27 THEN CLOSE #1 CLS PRINT "232SDAxx program has terminated." END END IF END SUB
ASKED: April 3, 2007  3:46 PM
UPDATED: April 3, 2007  4:39 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

when you talk to the device you are in a loop where you check to see if it responds in a certain time – you store the original time with t#=TIMER then loop with ” IF TIMER > t# + .5 THEN”

if the first call is at 11:59:59.999 then what is the value of TIMER at 00:00:00.001 ?

You need to use Now() which includes the day as integer and fraction of day as real portion, and look for a differecne of whatever half a second is.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BeerMaker
    your also missing error handling. I scanned for On Error conditions and you don't have any exception handling. Your obviously getting an exception at midnight and crashing. Put in some Error handling to recover from the error. If you try the code below in the immediate window of the debugger you get a type mismatch. Its possible this is your problem. ?cdate("24:00:000") 'this throws an error
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following