Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sjk/utf8 #16

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ julia:
- nightly
notifications:
email: false
sudo: true
sudo: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd())'
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.4
Compat
Compat 0.7.20
Docile
PyCall
StringEncodings
25 changes: 22 additions & 3 deletions src/SerialPorts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module SerialPorts
export SerialPort, SerialException, setDTR, list_serialports,
check_serial_access

using Compat, PyCall
using Compat, PyCall, StringEncodings
VERSION < v"0.4-" && using Docile

const PySerial = PyCall.PyNULL()
Expand Down Expand Up @@ -79,8 +79,27 @@ function Base.write(serialport::SerialPort, data::@compat UInt8)
serialport.python_ptr[:write](data)
end

function Base.write(serialport::SerialPort, data::SerialString)
serialport.python_ptr[:write](data)
function Base.write(serialport::SerialPort, data::UTF8String)
bytes = encode(data,"UTF-8")
if sizeof(bytes) == length(data)
serialport.python_ptr[:write](bytes)
else
i = 1
a = Array(Int64,1)
while i <= sizeof(data)
if sizeof(string(data[i:i])) == 2
if bytes[i] == 195 bytes[i+1] = bytes[i+1]+64 end
push!(a,i+1)
i = i+2
else
push!(a,i)
i = i+1
end
end
a = a[2:end]
bytes = bytes[a]
serialport.python_ptr[:write](bytes)
end
end

function Base.read(ser::SerialPort, bytes::Integer)
Expand Down