smartware 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,28 +45,29 @@ module Smartware
45
45
  # Don`t call with method synchronously from app, method waits USSD answer 3 sec,
46
46
  # Use some scheduler and buffer for balance value
47
47
  #
48
- def ussd(code="*100#")
48
+ def ussd(code="*100#", use_gets = false)
49
49
  port = SerialPort.new(@port, 115200, 8, 1, SerialPort::NONE)
50
50
  port.read_timeout = 3000
51
51
  port.write "AT+CUSD=1,\"#{code}\",15\r\n"
52
- ussd_body = port.read.split(/[\r\n]+/).last.split(",")[1].gsub('"','') # Parse USSD message body
52
+ result = use_gets ? port.gets : port.read
53
+ # Parse USSD message body
54
+ ussd_body = result.split(/[\r\n]+/).last.split(",")[1].gsub('"','')
53
55
  port.close
54
- ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join # Encode USSD message from broken ucs2 to utf-8
56
+ # Encode USSD message from broken ucs2 to utf-8
57
+ ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join
55
58
  rescue
56
59
  -1
57
60
  end
58
61
 
59
- private
60
- def send cmd
61
- @sp.write "#{ cmd }\r\n"
62
- answer = ''
63
- while IO.select [@sp], [], [], 0.25
64
- chr = @sp.getc.chr
65
- answer << chr
66
- end
67
- answer.split(/[\r\n]+/)
62
+ def send(cmd, read_timeout = 0.25)
63
+ @sp.write "#{ cmd }\r\n"
64
+ answer = ''
65
+ while IO.select [@sp], [], [], read_timeout
66
+ chr = @sp.getc.chr
67
+ answer << chr
68
68
  end
69
-
69
+ answer.split(/[\r\n]+/)
70
+ end
70
71
  end
71
72
 
72
73
  end
@@ -1,4 +1,8 @@
1
1
  # coding: utf-8
2
+ #
3
+ # Custom tg2480h printer functions
4
+ #
5
+
2
6
  require 'serialport'
3
7
 
4
8
  module Smartware
@@ -1,3 +1,3 @@
1
1
  module Smartware
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: