Тема: Android lib
Показать сообщение отдельно
Старый 08.08.2013, 16:33   #10
RegIon
Элита
 
Аватар для RegIon
 
Регистрация: 16.01.2010
Адрес: Новосибирск
Сообщений: 2,157
Написано 502 полезных сообщений
(для 1,012 пользователей)
Ответ: Android lib

http://answers.unity3d.com/questions...using-jni.html

Настрочил вызовы jni:
using UnityEngine;
using System;
using System.Runtime.InteropServices;

public class 
USB_Serial IDisposable {
    
    private 
AndroidJavaObject usb;
    private 
AndroidJavaObject dr;
    
    private 
AndroidJavaClass driver = new AndroidJavaClass("com.hoho.android.usbserial.driver.UsbSerialDriver");
    private 
AndroidJavaClass prober = new AndroidJavaClass("com.hoho.android.usbserial.driver.UsbSerialProber");
    
        
    private 
USB_Serial(){
        
using(AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){
            
using(AndroidJavaObject activity ajc.GetStatic<AndroidJavaObject>("currentActivity")){
                
usb activity.Call<AndroidJavaClass>("getSystemService",new object[] {"usb"});
                
dr prober.Call<AndroidJavaClass>("acquire",new object[]{usb}); 
            }
        }
    }
    
    private 
bool dropen false;
    public 
void Open(int speed,int dataBits,int flow,int parity){
        if(
dr!=null){
            
dr.Call("open",new object[0]);
        try{    
            
dr.Call("setParameters",new object[]{speed,dataBits,flow,parity});
            
dropen=true;
            }
            catch{
                
            }
        }    
    }
    
    public 
int Read(){
        
int read_c = -1;
        if(
dropen){
            
        }
        return 
read_c;
    }
    
    public 
void Dispose()
    {
        
usb.Dispose();
        
dr.Dispose();
    }
    
    public static 
readonly USB_Serial Port = new USB_Serial();

Сей возникла проблем с:
/**
     * Reads as many bytes as possible into the destination buffer.
     *
     * @param dest the destination byte buffer
     * @param timeoutMillis the timeout for reading
     * @return the actual number of bytes read
     * @throws IOException if an error occurred during reading
     */
    
public int read(final byte[] dest, final int timeoutMillisthrows IOException;

    
/**
     * Writes as many bytes as possible from the source buffer.
     *
     * @param src the source byte buffer
     * @param timeoutMillis the timeout for writing
     * @return the actual number of bytes written
     * @throws IOException if an error occurred during writing
     */
    
public int write(final byte[] src, final int timeoutMillisthrows IOException;

    
/**
     * Sets various serial port parameters.
     *
     * @param baudRate baud rate as an integer, for example {@code 115200}.
     * @param dataBits one of {@link #DATABITS_5}, {@link #DATABITS_6},
     *            {@link #DATABITS_7}, or {@link #DATABITS_8}.
     * @param stopBits one of {@link #STOPBITS_1}, {@link #STOPBITS_1_5}, or
     *            {@link #STOPBITS_2}.
     * @param parity one of {@link #PARITY_NONE}, {@link #PARITY_ODD},
     *            {@link #PARITY_EVEN}, {@link #PARITY_MARK}, or
     *            {@link #PARITY_SPACE}.
     * @throws IOException on error setting the port parameters
     */
    
public void setParameters(
            
int baudRateint dataBitsint stopBitsint paritythrows IOException
А именно с read, так как наверно прямо сделать так:
public int read(ref byte[] dataint ms) {
    var 
len dr.Call<int>("read",new object[]{data,ms});
return 
len;

НЕЛЬЗЯ.?

Так как тогда?
Сам класс тут.


UPD:
Вечно показывает подключенное устройство.
Не отправляет и не принимает .
__________________
Сайт: http://iexpo.ml

Последний раз редактировалось RegIon, 08.08.2013 в 19:02.
(Offline)
 
Ответить с цитированием