serial2, invalid format when sending file to COM port

pao

Member
I'm doing some tests to decide whether or not I use this software I have not yet purchased.
I print a plain text file through the serial port.

I built the file this way:

FileOpen (c1,"arch.txt",cWrite,,cASCII)
FileWrite (c1," " & txbNumero.Text)
FileWrite (c1,"")
FileWrite (c1,"NOMBRE ")
FileWrite (c1,"")
FileWrite (c1,"")

For i=0 To grid1.rowcount - 1
dato = grid1.Cell("CODE",i)
largo = StrLength(dato)
espacio = SubString (dato,(largo+1),(10-largo))
renglon = dato & espacio

dato = Format(grid1.Cell("IMPORT",i), "N2")
largo = StrLength(dato)
espacio = SubString (dato, (largo+1), (12-largo))
renglon = renglon & espacio & dato

FileWrite(c1, renglon)
Next i
FileClose (c1)

Then send it this way:

Serial.New1
Serial.CommPort = 6
Serial.BitRate = 9600
Serial.PortOpen = True
Serial.EnableOnComm = True

FileOpen (c1,"arch.txt",cRead ,, cASCII)
r = FileRead (c1)
Do Until r = EOF
Serial.Output(r)
sum = sum + r
r = FileRead (c1)
Loop
FileClose (c1)

Serial.PortOpen = False

But I have this problem:
Starts printing, it prints the number (txbNumero.Text), then the word NOMBRE and then gives an invalid format error.

It does not respect the line break. What is the code for line break?
Why give that format error?

I tested HP directly into a PDA and also on my pc, assigning the COM port to LPT1

I appreciate any help. If I can not fix this, I can not use this software.
Greetings.
 

edgar_ortiz

Active Member
Licensed User
Longtime User
You can try this:

Serial.New1
Serial.CommPort = 6
Serial.BitRate = 9600
Serial.PortOpen = True
Serial.EnableOnComm = True

FileOpen (c1,"arch.txt",cWrite,,cASCII)
FileWrite (c1," " & txbNumero.Text)
FileWrite (c1,"")
FileWrite (c1,"NOMBRE ")
FileWrite (c1,"")
FileWrite (c1,"")

For i=0 To grid1.rowcount - 1
dato = grid1.Cell("CODE",i)
largo = StrLength(dato)
espacio = SubString (dato,(largo+1),(10-largo))
renglon = dato & espacio
'
dato = Format(grid1.Cell("IMPORT",i), "N2")
largo = StrLength(dato)
espacio = SubString (dato, (largo+1), (12-largo))
renglon = renglon & espacio & dato
'
FileWrite(c1, renglon)
'
' Se Imprime
'
Serial.Output(renglon)
Next i
FileClose (c1)
'
' Close the printer
Serial.EnableOnComm = False
Serial.PortOpen = False
Serial.Dispose

Regards,

Edgar
 

mjcoon

Well-Known Member
Licensed User
"NOMBRE" is not convertible to a number so it is probably erroring here. I don't see what you are trying to do with this line of code:
sum = sum + r

Perhaps it was a mental hiccup which led pao to think that FileRead returns the number of characters read. The use of EOF to show end of file event supports this faulty view.

Whereas the FileRead help says: "Returns one line from an opened file." It cannot return both a string (such as "NOMBRE ") and a guaranteed number which can be accumulated in "sum".

Since sum is not used, just remove this line of code. Or substitute:

sum = sum + StrLength(r)

(If that is what is really wanted!)

Mike.
 

pao

Member
Hello all ..
Ohhhhhh. that line (sum=sum+r) is a bug! ...
That happened to copy / paste code internet!. Take it off and try again to test again when you have access to a serial printer.

In the test I did was printed number and name but there was no line break.
Why?
After formatting error occurred.

Thanks for answering!
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi,

You must send carriage return and line feed

renglon = renglon & chr(13) & chr(10)

Regards

Edgar
 

pao

Member
Hi Edgar
The FileWriter makes you think that adds a line break. (In the book says: "Text is the text to write to the next line in the file."

If you do:
FileWrite (arch, "aaa")
FileWrite (arch, "bbb")

and open the file in notepad you see:
aaa
bbb

if I add also the line break character, it will be another line blank.

Anyway, just prove to the page break that way.
Thank you very much
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi Edgar
The FileWriter makes you think that adds a line break. (In the book says: "Text is the text to write to the next line in the file."

If you do:
FileWrite (arch, "aaa")
FileWrite (arch, "bbb")

and open the file in notepad you see:
aaa
bbb

PAO,

It's correct, but remember one thing is the file 'arch' and another is your printer file.

Regards

Edgar

PS: where you from, I'm from Guatemala
 

pao

Member
Hello Edgar...
I'm from Uruguay.
With regard to access to a serial printer again, I will be testing. Thank you very much! I'll tell you how I worked

Spanish:
Hola Edgar. Soy de Uruguay.
En cuanto pueda acceder nuevamente a una impresora serial, volveré a hacer pruebas. Muchas gracias! Ya te contaté como me funcionó!.
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi pao,
tell me how you went and any problems send me an email, if I can help, will be a pleasure.

Regards,

Edgar


Spanish:

me comentas como te fué y por cualquier problema me mandas un email, si te puedo ayudar, será un gusto.
 
Top