Hi!
I am have a few POS handheld to print receipts and invoices sales. These devices are from China and has integrated a printer and CC reader.
I am trying to print to this printer but until now without sucess. I am using SerialLibJab to open the port, ttyMT0, and send the info but it doesnt work. The demo app in the device works fine so I checked this code and the diference between their code and our is they give 666 permision to ttyMT0 using chmod and su
<code>
/* Check access permission */
if (!device.canRead() || !device.canWrite()) {
try {
/* Missing read/write permission, trying to chmod the file */
Process su;
su = Runtime.getRuntime().exec("/system/bin/su");
String cmd = "chmod 666 " + device.getAbsolutePath() + "\n" + "exit\n";
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
throw new SecurityException();
}
} catch (Exception e) {
e.printStackTrace();
throw new SecurityException();
}
}
</code>
Apparently the problem is with permissions to the port. When I use the demo app first and my test after this works fine, I suposse the port has permissions, but if the device is off and I turn on when I use my app first doesnt work , I need to run the demo app first for my app can print
Now, my question :
There is a way to set permissions to the port directly from B4A ??
The code that I use to print to the printer is this
<code>
Dim Printer_AStream as AsyncStreams
Dim tr as textreader
Dim Buffer() as byte
Dim Success as Boolean
SerialPrinter.SetPort("/dev/ttyMT0",9600,0)
Printer_AStream.Initialize(SerialPrinter.InputStream,SerialPrinter.OutputStream,"Printer_Astream")
tr.Initialize(File.OpenInput(File.Dirdefaultexternal , "example.txt"))
buffer = tr.ReadAll.GetBytes("ISO-8859-1") 'Or other Iso Format
Success = Printer_AStream.Write(buffer)
</code>
This works fine as long as I run the demo app first.
Any cluees or idea about this ?
I am still thinking the problem is perimission
TIA
I am have a few POS handheld to print receipts and invoices sales. These devices are from China and has integrated a printer and CC reader.
I am trying to print to this printer but until now without sucess. I am using SerialLibJab to open the port, ttyMT0, and send the info but it doesnt work. The demo app in the device works fine so I checked this code and the diference between their code and our is they give 666 permision to ttyMT0 using chmod and su
<code>
/* Check access permission */
if (!device.canRead() || !device.canWrite()) {
try {
/* Missing read/write permission, trying to chmod the file */
Process su;
su = Runtime.getRuntime().exec("/system/bin/su");
String cmd = "chmod 666 " + device.getAbsolutePath() + "\n" + "exit\n";
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
throw new SecurityException();
}
} catch (Exception e) {
e.printStackTrace();
throw new SecurityException();
}
}
</code>
Apparently the problem is with permissions to the port. When I use the demo app first and my test after this works fine, I suposse the port has permissions, but if the device is off and I turn on when I use my app first doesnt work , I need to run the demo app first for my app can print
Now, my question :
There is a way to set permissions to the port directly from B4A ??
The code that I use to print to the printer is this
<code>
Dim Printer_AStream as AsyncStreams
Dim tr as textreader
Dim Buffer() as byte
Dim Success as Boolean
SerialPrinter.SetPort("/dev/ttyMT0",9600,0)
Printer_AStream.Initialize(SerialPrinter.InputStream,SerialPrinter.OutputStream,"Printer_Astream")
tr.Initialize(File.OpenInput(File.Dirdefaultexternal , "example.txt"))
buffer = tr.ReadAll.GetBytes("ISO-8859-1") 'Or other Iso Format
Success = Printer_AStream.Write(buffer)
</code>
This works fine as long as I run the demo app first.
Any cluees or idea about this ?
I am still thinking the problem is perimission
TIA