-
Notifications
You must be signed in to change notification settings - Fork 54
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
Examples needed #9
Comments
From at_test.go: package main
import (
"log"
"time"
"github.com/xlab/at"
"github.com/xlab/at/sms"
)
var dev *at.Device
// openDevice opens the hardcoded device paths for reading and writing,
// also inits this device with the default device profile.
func openDevice() (err error) {
dev = &at.Device{
CommandPort: "/dev/ttyUSB2", // or COM23 on windows
NotifyPort: "/dev/ttyUSB2", // or COM23 on windows
}
if err = dev.Open(); err != nil {
return
}
if err = dev.Init(at.DeviceE173()); err != nil {
return
}
return
}
func main() {
err := openDevice()
if err != nil {
log.Panicln(err)
}
defer dev.Close()
msg := sms.Message{
Text: "Your text message",
Type: sms.MessageTypes.Submit,
Encoding: sms.Encodings.UCS2,
Address: sms.PhoneNumber("+84902107791"), // Your phone number
VPFormat: sms.ValidityPeriodFormats.Relative,
VP: sms.ValidityPeriod(24 * time.Hour * 4),
}
n, octets, err := msg.PDU()
if err != nil {
log.Panicln(err)
}
err = dev.Commands.CMGS(n, octets)
if err != nil {
log.Panicln(err)
}
} How to send USSD command (to check Balance): package main
import (
"log"
"github.com/xlab/at"
"github.com/xlab/at/pdu"
)
var dev *at.Device
// openDevice opens the hardcoded device paths for reading and writing,
// also inits this device with the default device profile.
func openDevice() (err error) {
dev = &at.Device{
CommandPort: "/dev/ttyUSB2", // or COM23 on windows
NotifyPort: "/dev/ttyUSB2", // or COM23 on windows
}
if err = dev.Open(); err != nil {
return
}
if err = dev.Init(at.DeviceE173()); err != nil {
return
}
return
}
func main() {
err := openDevice()
if err != nil {
log.Panicln(err)
}
defer func() {
dev.Close()
}()
// Replace *101# by your USSD command
err = dev.Commands.CUSD(at.UssdResultReporting.Enable, pdu.Encode7Bit("*101#"), at.Encodings.Gsm7Bit)
if err != nil {
log.Panicln(err)
}
// wait for ussd reply
ussdReplyChan := dev.UssdReply()
ussdReply := <-ussdReplyChan
log.Println("USSD reply:", ussdReply.String())
} |
does this lib over delivery report? |
@vinhjaxt What is the best way to initiate multiple USB modems? |
Hey! I will point in the direction but didn't test it myself. You can create multiple configs like these to point to your different devices: dev = &at.Device{
CommandPort: "/dev/ttyUSB2",
NotifyPort: "/dev/ttyUSB2",
}
dev2 = &at.Device{
CommandPort: "/dev/ANOTHER_ttyUSB",
NotifyPort: "/dev/ANOTHER_ttyUSB",
} Then use |
I new to the go language I would like a simple example for sending messages using at package.
The text was updated successfully, but these errors were encountered: